TORONTO — The Boston Red Sox stumbled into Toronto mired in a four-game losing streak.

Thanks to some timely hitting from Mitch Moreland, they left Canada for a showdown in New York against the second-place Yankees riding high after a sweep of the struggling Blue Jays.

Moreland had a pinch-hit homer and drove in four runs, Hanley Ramirez added a solo blast and Boston beat Toronto 7-1 on Wednesday night.

“It’s a testament to the guys in our clubhouse,” Manager John Farrell said of the turnaround after his team was outscored 38-10 over its skid. “They’re driven, they’re task-oriented, they don’t dwell on what’s happened previously. We felt like we needed to do that, coming off a tough series where we got swept at home.”

Rick Porcello allowed one run in 62/3 innings as the AL East-leading Red Sox moved 51/2 games ahead of the Yankees, who were swept in a doubleheader by Cleveland. New York and Boston begin a four-game series at Yankee Stadium on Thursday.

“We definitely have a good feeling, obviously,” Porcello said.

Ramirez connected for the second straight game as the Red Sox finished 8-1 in Toronto this season. Boston is 10-3 overall against the Blue Jays with six meetings remaining at Fenway Park in September.

“They’re in first place for a reason,” Blue Jays left-hander J.A. Happ said of Boston. “They were tough this series.”

Pinch-hitting for Chris Young against right-hander Tom Koehler (1-7), Moreland hit a second-deck drive in the seventh, his 18th. It was the third pinch-hit homer of Moreland’s career.

Moreland added a two-run single in Boston’s four-run, bat-around eighth.

“Insurance runs are huge,” Moreland said. “It just helps everybody settle in a little bit more.”

Moreland is batting .346 (28 for 81) with 19 RBI in his past 27 games.

“He’s in a good place,” Farrell said.

Ramirez also reached the second deck with his homer, a leadoff shot off Happ in the fifth.

“The last couple of nights, he’s put some really good swings on some pitches,” Farrell said.

The homers helped Porcello (9-15) finish August at 5-1 with an ERA of 4.04.

Toronto’s only run came on a homer by Raffy Lopez in the third. The last-place Blue Jays lost for the 10th time in 12 games.

“Obviously it’s been real tough,” Manager John Gibbons said. “We haven’t played good enough baseball lately.”

NOTES: Boston went 11 for 11 in stolen-base attempts in the series. The Red Sox have 24 steals against Toronto this season, the most by any team against an opponent. … LHP David Price (left elbow) threw a 20-pitch bullpen session Wednesday. Price had not thrown off a mound since July 22 against the Angels, when he allowed six runs in five innings. … 2B Dustin Pedroia (left knee) ran the bases for a second straight day and remains on track to return during Boston’s upcoming series with the Yankees. … 3B Josh Rutledge had surgery on his left hip Tuesday and will miss the remainder of the season.