The A's trailed 3-1 with two outs in the ninth before rallying against closer Raisel Iglesias (1-1).
Ramon Laureano doubled and Christian Bethancourt walked before Barrera launched the drive into the right-field seats in his 17th career at-bat. Barrera had made an error in left field that allowed the Angels to score their third run and was double off first on a fly out to right field in the seventh.
"I didn't forget about it all game, but I wanted to make a difference once it was my turn, and my turn did come," Barrera said.
Lou Trivino (1-2) retired Mike Trout with two on and two out to end the ninth to earn the win.
Trout came off the bench and was part of a two-run rally that gave the Angels a 3-1 lead in the eighth.
Trout came on to pinch hit after Sam Moll walked Jared Walsh with one out. Zach Jackson intentionally walked Trout following a passed ball before pinch-hitter Anthony Rendon broke the tie with an RBI single to left.
Andrew Velazquez followed with a single to left and Trout came around to score after Barrera misplayed the ball for an error.
But the A's rallied for their first win when trailing after eight innings this season and their first walk-off win under manager Mark Kotsay.
"I haven't come down yet," Kotsay said. "It's a great feeling for this group. They don't give up. They fight through the end of the game every day, every night and I couldn't be prouder of that that group right now."
The Angels took the lead in the first on an RBI forceout by Shohei Ohtani but couldn't get anything else off Paul Blackburn in 6 2/3 innings. Blackburn has allowed one run or fewer in five of seven starts this season.
The A's tied it in the seventh on an RBI single by pinch-hitter Jed Lowrie.
The Angels got a couple of sharp defensive plays with Velazquez making a leaping grab to rob Kemp to lead off the game and center fielder Aaron Whitefield making a diving catch to rob Sean Murphy to end the sixth.
LET'S PLAY TWO
The A's are playing their second doubleheader of the week, having split a traditional twinbill in Detroit in Wednesday. This is the first time since 1986 that the A's played a pair of nine-inning doubleheaders in the same week.
Oakland had back-to-back twinbills at home against the Orioles on Aug. 28-29 that season following rainouts earlier that month in Baltimore.
"I got here at 8 this morning and I will be leaving here about 10:30 tonight. But it's baseball, right?" Kotsay said. "It's it's part of our game."
Angels: INF Matt Duffy re-joined the team after playing the last two nights on a rehab assignment in Triple-A. Manager Joe Maddon hasn't decided when Duffy will be activated after a stint on the IL with COVID.
Athletics: OF Stephen Piscotty (calf) has still not been cleared for baseball activity and isn't expected to be ready Tuesday when he's first eligible to come off the IL.
In the second game, RHP Adam Oller (0-2, 11.17) came up from Triple-A Las Vegas as the 27th man for the expanded doubleheader to face Angels RHP Michael Lorenzen (3-2, 4.13).
Luis Barrera walks it off for A's with 3-run HR
Luis Barrera hits a 3-run walk-off for his first career home run to give the A's a 4-3 win.