After losing six in a row and seeing their playoff chances fade, they beat the Houston Astros, 7-5, on Sunday night to restore a sliver of hope.

Thanks to the Minnesota Twins’ fourth consecutive victory, the Angels are still 4-1/2 games back in the wild card race, with seven games to play.

Any combination of three Angels losses and Twins wins will end it. Over the next few days, the Angels will have a chance to gain some momentum. They start a four-game series against the rebuilding Chicago White Sox on Monday, while the Twins have an off day before beginning a three-game series against the Indians in Cleveland.

The Angels can head to Chicago feeling better about their slumping offense, with 11 hits and five walks helping them overcome a third-inning 4-1 deficit.

Newcomers Justin Upton and Brandon Phillips each drove in two runs, including a homer apiece. It was Upton’s seventh homer with the Angels, his third in two days. The biggest hit came from Luis Valbuena, a two-run double in the seventh that capped an inning in which the Angels took advantage of some breaks.

Albert Pujols hit a blooper that dropped just inside the right-field line. Phillips then hit a routine double-play ball, but third baseman Alex Bregman booted it. Andrelton Simmons then hit a ball that ricocheted off Chris Devenski’s foot and rolled into the outfield, for a single to load the bases.

That brought up Valbuena, who battled Devenski through an 11-pitch at-bat. He capped it by yanking a changeup off the fence in right-center, driving in two.

The Angels’ bullpen made the lead stand. Cam Bedrosian gave up a solo homer in the seventh, but then Yusmeiro Petit and Blake Parker worked scoreless innings. For Petit, it was a bounceback outing after he’d allowed three runs in each of his previous two games.

Angels pitchers hadn’t had much experience pitching with leads in the last week.

The Angels scored first, when Upton beat out a potential double play to drive in a run in third. It was just the second time in the past seven games that they’d taken a lead.

Like the other time, though, it didn’t last long.

Back on Thursday, the lead was gone by the first batter of the next half inning. This time, Tyler Skaggs managed to get two outs before it all went wrong.

He hit George Springer with a pitch, gave up a two-run homer to Bregman, then walked Jose Altuve and Carlos Correa. An Evan Gattis double completed the four-run outburst.

Skaggs, however, tacked on two more scoreless innings, getting through five with just those four runs.

The Angels took him off the hook for the loss before he was done pitching. Phillips homered in the fourth. In the fifth, the Angels loaded the bases with two outs, and Phillips and Simmons both drew walks to push home runs, evening the score at 4.