Rivera got Lawrie to ground out, but things grew more complicated in the ninth.

The Blue Jays started the inning with two singles. Munenori Kawasaki bunted, but first baseman Lyle Overbay charged the ball and threw out the runner at third for the first out. The runners advanced when Ryan Goins grounded out to Robinson Cano. A solid single probably would have given Toronto the game and crushed the Yankees’ hopes for good, but Rivera struck out J. P. Arencibia to end the game.

“We have to be ready for any situation,” said Rivera, who earned his 44th save.

The Yankees’ 16-inning scoring drought, which began with Tuesday’s demoralizing shutout loss, finally ended in the eighth. Ryan doubled off starter J. A. Happ, who was replaced by the left-hander Aaron Loup. Curtis Granderson then singled to put runners at first and third with nobody out.

Blue Jays Manager John Gibbons summoned Steve Delabar to face Rodriguez, and Delabar struck him out. But Cano singled over the head of Goins at second base, and Ryan scored with the Yankees’ first run since the ninth inning of Sunday’s loss to the Red Sox. Granderson scored again for the Yankees — and cut their deficit to 3-2 — when Soriano doubled off the wall in right field.

It was up to Wells. He doubled to the corner in left field, Cano and Soriano scored, and the Yankees finally took a lead.

Asked if he was surprised to be allowed to hit in that situation, Wells paused for a moment, smiled and said, “I was just happy to have the opportunity.”

Even Soriano, who said after Tuesday night’s loss that the Yankees did not have the proper energy, was pleased. Still, he demanded more.

“That was a very important game, and through the seventh inning we didn’t do nothing,” he said. “Now, tomorrow, we have to score early and take some pressure off the pitchers.”