NEW YORK — A day after being shut out on three singles, J.J. Hardy and the Baltimore Orioles got blanked for six innings Sunday on what was shaping up as a lost weekend.
‘‘We were a little flat. We could all see it, we could all feel it,’’ Hardy said.
That all changed in a hurry.
Hardy and Adam Jones hit three-run homers during a seven-run burst in the seventh as Baltimore suddenly broke loose, jolting the Yankees, 7-3, to avert a sweep in a matchup of wild-card contenders in New York.
‘‘Hopefully, it jump-starts us in September,’’ Hardy said.
The Orioles rallied against Andy Pettitte and a faltering bullpen. Michael Morse lined a leadoff single to begin the comeback from a 3-0 deficit. Acquired from Seattle on Friday, he got two hits in his Baltimore debut.
‘‘We just needed a little spark there,’’ Morse said.
Hardy’s shot against Shawn Kelley (4-2) glanced off the glove of right fielder Curtis Granderson and put the Orioles ahead, 4-3.
After reliever Boone Logan gave up a bunt single and walk, Jones homered to dead center field against Joba Chamberlain.
‘‘It was tough today. A chance for us to sweep and it is completely on me,’’ Kelley said.
The seven runs matched the Orioles’ biggest inning of the season. It also tied the most allowed by the Yankees in an inning this year.
‘‘We needed it big,’’ Jones said. ‘‘Things hadn’t fallen into place.’’
The Orioles won for the second time in six games on a road trip that includes three more games at Cleveland.
The Yankees had beaten Baltimore two in a row while extending their home winning streak to six. New York had been 32-0 at home this year when leading by at least two runs, the Elias Sports Bureau said in research provided by the Yankees.
Rookie Kevin Gausman (2-3) pitched two scoreless innings after starter Wei-Yin Chen walked a career-high five on a sticky afternoon.
Four Baltimore relievers combined for five shutout innings.
Pettitte has beaten Baltimore 29 times in the regular season and playoffs, and seemed to be cruising through six innings. He had walked none, worked around five singles, and wasn’t in trouble.
But Morse and Danny Valencia opened the seventh with sharp singles, and Yankees manager Joe Girardi made the first of several trips to the mound.