TORONTO — After going hitless for almost an entire week, Jackie Bradley Jr. came up big for the Boston Red Sox on Saturday.

David Ortiz singled home the go-ahead run in a five-run ninth inning and the Red Sox rallied to beat the Toronto Blue Jays 7-6.

Bradley snapped an 0-for-21 slump with a game-tying double in the seventh, then tied it again with a two-run homer off Roberto Osuna (1-5) in the ninth. He had gone 1 for 32 before the two hits, and had been hitless since a fourth-inning double against Tampa Bay on Sept. 12.

“It felt good,” Bradley said. “It felt like I finally made solid contact.”

Interim manager Torey Lovullo praised Bradley for putting his slump aside and producing.

“It showed signs of maturity that he can put that behind him despite the tough circumstances,” Lovullo said. “I know it was a big day for him and he’s very excited.”

Twenty-four of Bradley’s last 33 hits have gone for extra bases, including 15 doubles and seven home runs.

It was the first time in 74 such situations this season that the Blue Jays lost when leading after eight innings.

Xander Bogaerts also homered for the Red Sox, who are 9-9 against Toronto this season. The Blue Jays’ lead in the AL East dropped to 3 1/2 games over the Yankees.

“Anytime we can win against the best right now, that’s always a positive,” Bradley said.

One out after Bradley’s homer, Dustin Pedroia walked, and Osuna was replaced by Aaron Sanchez.

“I’ve got to do a better job,” Osuna said. “I’ve got to locate my fastball better.”

Bogaerts singled to right and Ortiz followed with an RBI single to left.

Bogaerts made it 6-4 when he scored on a wild pitch, and Rusney Castillo added an RBI single to center, chasing Sanchez.

Tommy Layne (2-1) pitched two-thirds of an inning for the win, and Robbie Ross overcame Jose Bautista’s two-run homer in the ninth to earn his third save.

Pinch-hitter Matt Hague doubled with two outs, but Ross ended it by getting pinch-hitter Justin Smoak to ground out.

Toronto’s Edwin Encarnacion went 2 for 3 with a homer and three RBI, including a go-ahead single in the eighth.

After striking out in his first two at-bats, Bogaerts opened the scoring with a leadoff homer off R.A. Dickey in the sixth, his sixth of the season.

The Blue Jays answered in the bottom half when Encarnacion hit one off the facing of the second deck in left for a two-run homer, his 34th.

Dickey left after Brock Holt’s ground-rule double to begin the seventh. Mark Lowe came on and got Blake Swihart to ground out, with Holt advancing to third. With the infield in, Bradley followed with a chopper off the glove of diving second baseman Cliff Pennington that ricocheted into shallow right.

“Anything would have helped,” Bradley said when asked if the hit boosted his confidence. “I’m just glad that I was able to get something going to help the team.”

Toronto broke the tie with two runs off Noe Ramirez in the eighth, on RBI singles by Encarnacion and Kevin Pillar.

Dickey allowed two runs and six hits in six-plus innings. Boston’s Wade Miley gave two runs and three hits in 6 2/3 innings.