Aaron Judge, right, drove in Brett Gardner with a two-run homer in the 13th inning on Wednesday to give the Yankees a lead they wouldn’t relinquish.CreditFrank Gunn/The Canadian Press, via Associated Press

TORONTO — The Yankees get a lot of attention for their prowess at the plate, and deservedly so. But through 12 innings on Wednesday, it was a pitching show led by Sonny Gray, with the Yankees defense playing a stout supporting role against the Blue Jays.

It looked like it was going to be a night to forget for Aaron Judge, who had returned to the lineup on Wednesday after a night off. Judge was hitless in his first four at-bats as Gray held things together while the sluggers struggled.

Finally, in the 13th inning, the Yankees’ bats jolted to life against reliever Joe Biagini. Judge delivered a two-run homer — his 17th of the season — to center field to break open a scoreless game, and Giancarlo Stanton followed with a solo shot over the left-field wall to give the Yankees a 3-0 cushion that they carried to a victory.

Judge was a bit of an unlikely savior. He had struck out eight times in Monday’s doubleheader in Detroit and had generally been scuffling at the plate in the past few weeks. Since May 15, he had batted .197 with 29 strikeouts in 76 plate appearances entering Wednesday.

It took eight strong innings from Gray and solid defense just for the Yankees to stay in the game through the 13th. It was the second strong outing on the mound for the Yankees after C.C. Sabathia had gone seven innings in a 7-2 victory on Tuesday.

Despite the tied score, Gray had a little strut in his step when he left the mound, the result of allowing just two hits and two walks while striking out eight. He threw 99 pitches, 63 of them strikes.

Some sharp defense also helped his mood. The Yankees ended the fifth and sixth innings with double plays to end Blue Jays threats.

Gray’s performance was an encouraging sight for the Yankees when they needed it. They had announced on Tuesday that pitcher Jordan Montgomery would be gone for the season because of Tommy John surgery.

Image

Sonny Gray gave up just two hits and struck out eight over eight innings. CreditNick Wass/Associated Press

Gray has had trouble living up to expectations after he was acquired last July at the trade deadline from Oakland.

He was viewed as the final piece in another Yankees championship puzzle, and the club gave up three prized prospects to get him.

But, while Gray, 28, has had some skittish starts this season, there had been seeds of progress in his recent performances before Wednesday. In Baltimore on June 1, he hurled six strong innings in a 4-1 victory over the Orioles, and going into Wednesday he had won two of his previous three starts.

Gray has also shown he can go deep into games, lasting at least five innings in six of his previous seven outings. In his first five starts, he had made it past the fifth inning only once.

He was sharp from the start on Wednesday, starting his night with a nasty curve ball. In the first inning, he got Teoscar Hernandez to bite on a swinging strike for the third out. It was Hernandez who had slammed a solo home run off Sabathia the night before.

The Yankees’ hitters did have their chances. In the 11th inning, Blue Jays reliever John Axford threw two wild pitches, which put Stanton at third with two out. But Gary Sanchez’s struggles at the plate continued when he came up and went down swinging.

In the previous inning, it was the rookie Miguel Andujar at center stage again. Andujar had provided a spark on Tuesday with a grand slam, and he kicked off the 10th inning on Wednesday with a double. But nothing came of it.

The Blue Jays also got a strong start, from Sam Gaviglio, and tight defense to keep the game scoreless through 12. Gaviglio, who had been called up from Class AAA Buffalo last month, went seven innings, allowing three hits and three walks while striking out four.

The Yankees’ road trip continues on Friday, but they’ll be close to home: at Citi Field, facing the Mets for four games. Manager Aaron Boone is looking forward to a fresh environment in the Subway Series.

“We’re actually going home, so that will be kind of cool to be going from home into another ballpark and putting on the grays,” Boone said. “I know the city will be excited about it, and I know the fan base will obviously be excited about it. I’m very much looking forward to it.”