TORONTO — As Sunday dawned Masahiro Tanaka understood the importance of working deep into the game against the Blue Jays.

He knew Aaron Boone had put Adam Ottavino in dry dock after the right-hander worked a stressful inning Saturday so the middle–to-late-game bullpen consisted of Zack Britton and Aroldis Chapman.

Then there was a doubleheader looming Monday with a reliever being used as a starter in the second game. And as Sunday’s game unfolded Tanaka, and everybody else in the Yankees’ dugout, understood the visitor’s run in the fifth might be the only one.

Tanaka, who had mostly struggled in his past seven starts, responded like a staff ace by getting into the ninth inning with the lead.

“It was really big because if we were in any kind of leverage spot in the middle or late part of the game we were only going Britton, Chappy today. We wanted to stay away from [Luis] Cessa and Nestor [Cortes Jr.],’’ Boone said after a 1-0 Yankees victory that was witnessed by 27,790 at Rogers Centre. “It was just what the doctored ordered. Masa came out and was really pitch efficient, especially in the middle innings he was cruising, and we needed it.’’

From June 29 to Aug. 5, Tanaka gave up 48 hits (nine homers) and 13 walks in 31 ²/₃ innings. His ERA was a bloated 10.23 and hitters batted .340 against him.

On Thursday, he said it was up to him to change the narrative by being more consistent. Working without much run support and in front of a short bullpen, he was more than that.

“Obviously we are going through a long stretch of games right now,’’ Tanaka said of the Yankees playing 19 games in 17 days. “Bullpen days and what is coming [Monday]. Coming into the game you feel like you want to go longer.’’

Tanaka’s splitter has improved in his past three starts after he changed the grip on the signature pitch, but his slider and fastball were his most effective pitches Sunday.

“I didn’t plan on throwing a lot of sliders. It was more of having a good feel for it and looking at the hitters and seeing what they are trying to do,’’ said Tanaka, who improved to 8-6 with his first victory since July 20. He allowed three hits in eight-plus frames, didn’t issue a walk and whiffed four.

Tanaka came within three outs of posting a second complete game, but when Brandon Drury opened the ninth with a ground single to left Boone called for Chapman, who had last pitched Aug. 5.

Chapman won a high-intensity, 13-pitch at-bat with pinch-hitter Vladimir Guerrero Jr. and got him to hit into a 6-4-3 double play. Bo Bichette extended the game with a single to left but Chapman overpowered Cavan Biggio for his 31st save in 36 attempts.

“It was the best at-bat on both sides of the ball, one of their better hitters and our closer getting after it,’’ catcher Austin Romine said. “Especially when it ends in a double play.’’

The victory sent the Yankees home with a 5-2 road trip that originated in Baltimore where they took three from the awful Orioles, who open a four-game series at Yankee Stadium with a doubleheader Monday.

It also moved the Yankees nine lengths ahead of the second-place Rays in the AL East pending the outcome of the Rays-Mariners game.

While Tanaka was dominating the Yankees struggled for the third straight game against the Blue Jays’ no-name staff. The only run of the game came in the fifth when Gio Urshela blooped a double into center field and Brett Gardner followed with an RBI ground-rule double to right.

Tanaka is no longer viewed as the ace of a staff that doesn’t have one. However, a few more outings like Sunday’s and he might reclaim that title.