Hernandez came up with the bases loaded and grounded a single into left field. Pinch runner Santiago Espinal scored easily and Randal Grichuk slid in safely just ahead of the throw by left fielder Mason Williams.
''I knew they would try to throw (inside),'' Hernandez said. ''My plan was to get a pitch middle inside the plate and try to put a good swing on it. I was thinking to pull the ball and get the barrel on the ball.''
Toronto also won Friday night on a game-ending hit. It has four such wins in 12 home games in Buffalo.
''I just talked to my parents and they said I'm putting them through this every game,'' Blue Jays manager Charlie Montoyo said. ''Stay in shape, keep those hearts going, because its every game. I've never seen anything like it. It's fun when you're winning games like this.''
Orioles manager Brandon Hyde took some consolation is how his team stayed in the game, taking leads on three separate occasions.
''I'm proud of our guys coming back and taking the lead in the top of the ninth,'' Hyde said. ''We just didn't finish it.''
Cole Sulser (1-4), who surrendered a game-ending homer to Grichuk on Friday, issued three walks and surrendered Hernandez's hit to take the loss.
Jose Iglesias delivered a go-ahead RBI single on a dribbling infield single in the top of the ninth inning against Toronto reliever Anthony Bass (2-1).
Ryan Mountcastle hit his first two big league homers for Baltimore, which lost its fifth straight. Mountcastle had three hits to run his average to .393 (11 of 28) since making his major league debut on Aug. 21.
Toronto earned its fourth straight win. Vladimir Guerrero Jr. extended his career-best hitting streak to 12 games, and Hernandez had two hits to extend his hit streak to 11 games, also a career high. Cavan Biggio extended his on-base streak to 22 games with an RBI single in the fifth inning.
Mountcastle led off the second with a towering drive to left. He hit a two-run shot in the sixth to give Baltimore a 4-3 lead. Both homers came off Toronto starter Tanner Roark.
''I finally got a ball in the air,'' Mountcastle said. ''Today my swing felt pretty good, and it was definitely enjoyable.''
Iglesias, Renato Nunez and Pedro Severino each had two hits for the Orioles, who dropped to 0-6 against Toronto this season.
Toronto tied it at 4 with two out in the eighth, getting a Hernandez single and Guerrero walk before Rowdy Tellez came through with an RBI single.
The Orioles completed two trades, dealing right-hander Tommy Milone to Atlanta for two players to be named and sending right-hander Mychal Givens to Colorado for infielders Terrin Vavra and Tyler Nevin and a player to be named or cash considerations.
Milone went 1-4 with a 3.99 ERA over six starts in his first season with the Orioles. Givens, 30, spent parts of six seasons with Baltimore.
Vavra, 23, was a third-round pick by the Rockies in the 2018 draft. Nevin is the son of former big league slugger Phil Nevin.
Right-hander Hunter Harvey and lefty Keegan Akin took over Baltimore's vacant roster spots. The trade deadline for the pandemic-shortened season is Monday.
''Young clubs get even younger at the deadline,'' Hyde said. ''We're young already and we're going to stay inexperienced for this last month, and we'll do the best we can with the guys we have.''
Orioles: Harvey (forearm strain) was activated from the IL, leaving three players on the 10-day injury list: RHP Shawn Armstrong (left SI joint inflammation), INF Chris Davis (left knee patellar tendinitis), and OF Austin Hays (non-displaced rib fracture).
Blue Jays: SS Bo Bichette (sprained knee) took ground balls, ran sprints, and hit in the cage. ... Closer Ken Giles (forearm strain) felt good after a bullpen session, and Montoyo envisions ''at least two more live batting practices before he comes back.'' Montoyo added: ''If he looks like he did before, there's no reason why he wouldn't be our closer again.'' ... RHP Nate Pearson (elbow tightness) and RHP Matt Shoemaker (shoulder inflammation) played catch from 90 and 60 feet, respectively.
Orioles: Rookie LHP Keegan Akin (0-0. 8.10 ERA) will take over the spot originally scheduled for Milone and make his first major league start in his third career appearance on Monday against the Blue Jays.
Blue Jays: RHP Chase Anderson (0-0, 3.68 ERA) will start in Monday's finale of the four-game series.
More AP MLB: https://apnews.com/MLB and https://twitter.com/AP-Sports
Copyright 2020 STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.