HOUSTON -- The Astros were in desperate need of a win Wednesday after dropping four of five and letting their lead in the AL West dwindle.
Held scoreless through seven innings, things looked bleak before some late-game heroics lifted them to the victory.
Mauricio Dubon's RBI single with one out in the ninth gave the Astros to a 2-1 win over the Baltimore Orioles, allowing Houston to avoid a sweep and stay a half-game ahead of Texas and Seattle for first place in the AL West standings.
"That was a big win," manager Dusty Baker said. "It was nice to see the guys happy and partying because it's been a morgue in there for the past two days. That was a huge game."
Yainer Diaz doubled to right field off Danny Coulombe (5-2) to start Houston's ninth, and he moved to third on a groundout by Chas McCormick.
Dubon smacked a single into the gap in right field to score Diaz and start the celebration.
"We needed this," Dubon said. "Getting a walk-off win in late September with how the standings are, it's pretty special for everybody."
The Astros had just two hits when Jeremy Peña's RBI double tied it with one out in the eighth.
Closer Ryan Pressly (4-5) pitched a scoreless ninth for the win.
Veteran catcher Martín Maldonado said nothing had to be said before the game for the Astros to know the urgency they need to play with as the regular season winds down.
"Everybody knows we have to win games, and nobody has to say anything for us to know that we've got to win games, and that's the bottom line," he said.
Anthony Santander doubled and drove in Baltimore's only run with a single in the first inning. The Orioles maintained their 2½-game lead in the AL East over Tampa Bay, which lost to the Los Angeles Angels later Wednesday.
Orioles starter Kyle Bradish allowed two hits and struck out nine in six scoreless innings.
Houston's Cristian Javier gave up five hits and a run while tying a season high with 11 strikeouts in five innings.
"That was the best that Javi has looked this year," Baker said. "He looked like the old Javier."
Adley Rutschman doubled with one out in the first before the Orioles made it 1-0 when he scored on a single by Santander.
Javier settled down after that, retiring 10 of the next 11 before Adam Frazier singled with one out in the fifth. Javier walked Ramon Urias but struck out Gunnar Henderson before retiring Rutschman to end the threat.
McCormick singled to open Houston's third, but Bradish didn't allow another hit until Jake Meyers singled to start the sixth.
He moved to second on a sacrifice bunt by Maldonado. Bradish struck out Altuve and looked to have struck out Peña to end the inning. But Rutschman was called for catcher's interference to put Peña on first and extend the inning. The Astros still came up empty when Kyle Tucker lined out.
"Tough lineup to pitch against, and he was outstanding," manager Brandon Hyde said. "Only gave up a couple hits, worked out of that jam there, got the unfortunate catcher's interference but a big out against Tucker there to end that inning. He was really good ... and deserved a win."
Shintaro Fujinami walked pinch-hitter Yordan Alvarez with no outs in the eighth before walking Jose Altuve with one out. He was replaced by Mike Baumann, who was greeted with the double from Peña that tied it at 1-all.
Baumann intentionally walked Tucker to load the bases, but Alex Bregman struck out before Jose Abreu grounded out to end the inning.