OAKLAND, Calif. (AP) Jed Lowrie is still adjusting to playing third base for the Astros. His throwing error in the ninth inning that led to a pair of unearned runs was a perfect example.

His swing, however, is as sound as it's been all season.

Lowrie hit an RBI double off Edward Mujica with two outs in the 10th to make up for his costly miscue, and Houston beat the Oakland Athletics 5-4 on Thursday night.

More from FoxSports

''We needed that,'' Astros manager A.J. Hinch said. ''If we ever needed a reminder on how hard it is to get wins . that's one of them. A much-needed win. We were tested in every way.''

Carlos Correa launched a go-ahead homer in a three-run eighth that gave the Astros a 4-2 lead. But the AL West leaders had to rally again after the A's scored twice off closer Luke Gregerson in the ninth.

Lowrie aided the Oakland comeback with a wild throw from third base. But the former Oakland shortstop, who drove in Houston's first run with a sacrifice fly, came through an inning later.

Jose Altuve led off the 10th with his third hit. He stole second on a pitchout and was sacrificed to third by Carlos Gomez. Mujica (2-4) retired Correa on a popup before Lowrie doubled to left field.

''I felt like I put us in that situation in the ninth,'' Lowrie said. ''Just grateful for the opportunity to come up there in the 10th and come through.''

Gregerson (5-1) was credited with the win after his fourth blown save in 26 chances. Will Harris got three outs for his first major league save, helped by a fine play from Altuve at second base.

It was the fourth time this season Houston won when trailing going into the eighth.

''That's the mark of a good team,'' Lowrie said. ''For us to come back and win this one, that's a good first step.''

Stephen Vogt and Brett Lawrie homered for Oakland, which wasted a strong outing by rookie Aaron Brooks.

Both teams blew late leads.

The A's were up 2-1 heading into the eighth before Correa hit a two-run homer off reliever Felix Rodriguez.

It was Correa's second home run in four days and sixth in the last 10 games. The 20-year-old rookie is the youngest position player in the majors and the only shortstop in the last century to hit 14 home runs in his first 51 games.

After Correa's drive gave Houston a 3-2 lead, Lowrie walked and scored when Colby Rasmus singled softy to left-center and the ball got past Billy Burns for an error.

Gregerson couldn't make it hold up.

He issued a leadoff walk before Lowrie's throwing error put runners at the corners with none out. Ike Davis hit an RBI single, and Burns drove in the tying run when he barely beat out a potential double-play grounder.

''It's tough. We've lost many games like this this year,'' Oakland manager Bob Melvin said. ''It comes down to a bunch of little things. We came up a little short. We've done that a lot this year.''

Brooks, part of the July 28 trade that sent Ben Zobrist to Toronto, gave up four hits and had a career-high seven strikeouts in seven innings. He allowed only two runners over his final five innings and left with a 2-1 lead.

Vogt homered off Houston starter Scott Feldman in the second. Feldman gave up two runs and five hits in six innings.

Lawrie homered leading off the fifth.

TRAINER'S ROOM

Astros: OF Preston Tucker did not start for the second straight game due to a bruised right arm. He entered on defense in the late innings. ... RHP Dan Straily was sent to Triple-A Fresno. Straily was designated for assignment Wednesday and cleared waivers.

Athletics: Former closer Sean Doolittle (left shoulder strain) will begin a rehab assignment with Class A Stockton on Friday. ... LF Coco Crisp (neck) and RF Josh Reddick (back) returned to the starting lineup.

UP NEXT

Astros: LHP Dallas Keuchel (13-5) seeks his AL-leading 14th win Friday when he faces the A's for the third time this season. In his previous two starts against Oakland this year, Keuchel has allowed only one unearned run in 16 innings.

Athletics: RHP Sonny Gray (11-4) has a 1.17 ERA over his past three starts but just one win and two no-decisions to show for it.