Houston ended a 10-game losing streak against the A's this season and a six-game skid overall.
The Astros trailed 4-2 entering the ninth before Matt Dominguez hit a two-run homer off closer Grant Balfour (0-2) to tie it.
Justin Maxwell hit an infield single to start the inning and advanced to second when Balfour attempted to make a throw to first from his knees and bounced it in the dirt for an error.
The homer by Dominguez bounced off the wall in left-center as Coco Crisp desperately tried to climb to grab it.
The home run ended a franchise-record streak of 44 saves for Balfour, the sixth longest run in major league history. It was his first blown save since April 29, 2012.
Villar, who was playing his second major league game, doubled with one out, and Jose Altuve walked before the defensive miscue ended it.
Brandon Moss put Oakland on top 4-2 with a two-run homer in the eighth inning.
Josh Fields (1-1) pitched a scoreless ninth for the win.
The game was tied 2-2 when reliever Jose Cisnero plunked Josh Donaldson with two outs. Moss then sent a 95 mph fastball into the second deck in right field for his 17th homer.
Houston starter Jarred Cosart, yielded seven hits and two runs — one earned — in seven innings in his second major league start after being recalled from Triple-A Oklahoma City on Tuesday.
Cosart, Houston's top pitching prospect, grew up in the Houston suburb of League City. He left more than 60 tickets for friends and family to see his first major league game in Houston.
Oakland starter Jarrod Parker allowed five hits and one earned run in seven innings.
John Jaso walked with one out in the first inning and Jed Lowrie followed with a single. Josh Donaldson singled, but Jaso was out at third on the play.
The Athletics took a 1-0 lead when Moss reached on an error by third baseman Matt Dominguez that allowed Lowrie to score.
Rookie Jonathan Villar got things going for Houston with a double in the first. The Astros tied it at 1-1 with back-to-back singles by Altuve and Jason Castro.
The bases were loaded in the third when Moss grounded into a double play that Coco Crisp scored on to put Oakland up 2-1.
The 23-year-old Cosart took a no-hitter into the seventh inning and got the win in his debut against Tampa Bay just before the break, allowing two hits and no runs in eight-plus innings. He was sent to Oklahoma City after that game.
He wasn't as sharp early on Tuesday, but starting rolling in the fourth, pitching a 1-2-3 inning. Crisp singled with one out in the fifth, but Cosart faced the minimum in that inning after Houston turned a double play. Donaldson hit a one-out double in the sixth before Cosart retired the next two batters to end the threat.
Pinch-hitter Yoenis Cespedes grounded into a double play in the seventh to erase a leadoff walk by Chris Young. Eric Sogard doubled, but Cosart finished his night by battling Crisp on a seven-pitch at-bat before he struck him out looking, leaving Crisp angrily shaking his head at the plate.
Barnes robbed Young of a hit with a nifty diving catch in center field in the fourth inning.
NOTES: The series wraps up on Wednesday when Oakland's A.J. Griffin opposes Bud Norris ... CF Barnes left before the seventh with a mild left calf strain. ... Cespedes, the Home Run Derby champ, was out of the starting lineup for the fifth straight game because of a sore left wrist. ... A's LHP Brett Anderson, on the disabled list since May 1 with a stress fracture in his right foot, is scheduled to throw 45 pitches in a bullpen session on Wednesday. He felt good after throwing 35 pitches on Monday. ... Longtime former Astros announcer Milo Hamilton, who had the memorable call on Henry Aaron's 715th home run, said Tuesday that he is giving up on his quest to call a game from his 60th ballpark because he is no longer able to fly because of poor health. Though he retired at the end of last season, he had hoped to travel to Target Field in Minnesota so he could reach the milestone. He is currently undergoing chemotherapy for treatment of a chronic form of leukemia he has had since the 1970s, but says he is feeling good.