Zach Britton converted his 55th straight save situation, setting an American League record, as the Orioles beat the Astros, 9-7. (Greg Fiume/Getty Images)

Zach Britton entered in the ninth inning of the Baltimore Orioles’ 9-7 comeback win over the Houston Astros on Sunday afternoon and was asked to do what he had done 54 straight times: get the save.

The Orioles had led by three runs two different times at Camden Yards, and both times the Astros had come back to tie it. Now Britton faced Houston’s three, four and five hitters — the heart of the lineup for the best offensive team in Major League Baseball.

Britton struck out Yuli Gurriel on seven pitches, then Evan Gattis on three. After Marwin Gonzalez walked, George Springer, who has 27 home runs this season, stepped up, representing the tying run.

Britton got him to ground into a forceout to second base. With that, the Orioles (47-51) avoided getting swept for the second time in three series and finished their homestand 5-5. And with that, Britton earned his 55th consecutive save, an American League record.

“I feel proud that a lot of us are here to see all of them and realize how hard that is to do, especially over that long period of time,” Baltimore Manager Buck Showalter said.

Getting the ball into Britton’s hands was a challenge for the Orioles.

The game was tied at 7 before Manny Machado hit a sacrifice fly to left field in the eighth inning, scoring Ruben Tejada from third.

Jonathan Schoop, the next batter, then brought in Adam Jones from second with a single for an insurance run.

The Orioles twice had three-run leads but had to keep the Astros (65-33), who lead the majors in runs, hits and home runs, from doing what they had done all series: rally.

The worst pitching staff in the AL had no luck.

The Astros erased deficits of 3-0 in the third and 6-3 in the sixth, both times with three-run home runs.

Jose Altuve went deep in the third, and Norichika Aoki’s came in a four-run sixth inning that gave Houston its first lead.

Both homers came off Dylan Bundy, who was coming off one of his best starts of the season: one run over six innings in a win against the Texas Rangers on Tuesday. As in that game, the Orioles’ offense gave him an early cushion. Except this time he allowed seven runs on eight hits in 5⅓ innings and was in danger of being the loser when he left after walking Jake Marisnick.

“I was just leaving stuff over the middle of the plate today,” Bundy said. “I was kind of lucky they only hit two homers off me.”

The Orioles scored three times in the second inning. Chris Davis singled, and Baltimore loaded the bases after Trey Mancini was drilled and Caleb Joseph walked. Hyun Soo Kim then took a pitch off his right thigh, scoring Davis. After Ruben Tejada grounded into a double play to score Mancini, Adam Jones singled home Joseph and Baltimore led 3-0.

After Houston tied the game in the third, Baltimore retook the lead in the bottom of the inning on a Mancini RBI single and added two more in the fifth on Davis’s sacrifice fly and a double by Mancini.

The lead wouldn’t last. But unlike the past two nights, Baltimore rallied. Mark Trumbo tied it in the seventh with a home run, and Machado gave the Orioles the lead in the eighth, setting up Britton’s save in the ninth.