Olly Barkley kicked his sixth penalty in the last minute as Bath beat London Irish by a single point.
Sailosi Tagicakibau's try and Chris Malone's penalty gave the home side an early 10-point lead, before two quick Barkley kicks closed the gap.
Richard Thorpe and Michael Claassens traded tries, before Barkley's third gave Bath the lead for the first time.
Topsy Ojo's try put London Irish ahead again, but Barkley scored two penalties in the last 10 minutes to win the game.
The result was Bath's first victory in the Premiership since late September, while London Irish have now lost nine in a row in all competitions.
The visitors fell behind after just two minutes despite winning a lineout - they lost possession and Tagicakibau smashed through two attempted tackles before touching down one-handed.
Ex-Bath player Chris Malone put over the conversion and then kicked a penalty, as the home side led 10-0 after only seven minutes.
Barkley's first penalty attempt for Bath gave no sign of what was to come as he missed a straightforward attempt on 28 minutes, but three minutes later he found his length from 50 metres and then added a second four minutes later.
Any thoughts of a first-half comeback were dispelled when Delon Armitage broke on the outside and Thorpe went over from his inside pass.
Malone converted for a second time, but moments later Barkley added a third penalty to close the gap again, although the home side were well in control with a 17-9 lead at the break.
Bath grew in confidence in the second half and Thorpe was shown a yellow card for the home side for collapsing a maul inside his own 22.
After a television replay ruled out an effort from Simon Taylor, Claassens scored Bath's first try with a dart through the middle, and Barkley's conversion cut the deficit to a point.
Barkley's 64th minute penalty put the visitors ahead for the first time, but London Irish stormed back as Sellala Mapusua's hard work set up Ojo to go over for a score, which Daniel Bowden converted.
Nine minutes from time Barkley's fifth penalty made it a two-point game and the same man stepped up with seconds remaining to stun the home side.
London Irish boss Toby Booth: "When you score three tries and concede one, you expect to win the game.
"I have got a dressing room full of people in disbelief. I felt we did enough to win the game, but we didn't.
"Discipline has cost us the game."
Bath head coach Steve Meehan: "It's a good result. There will be plenty of smiles and we've got to build on this now for next week against Leeds.
"I know how much hard work the players have been doing, and it's great to get the monkey off our back.
"In a tight competition like the Premiership it can be the bounce of the ball or one error that decides things.
"From our point of view, I knew it would turn around, I knew the win would come."
London Irish: D Armitage; Ojo, Seveali'i, Bowden, Tagicakibau; Malone, Hodgson (capt); Corbisiero, Buckland, Rautenbach; Kennedy, Garvey; Thorpe, Armitage, Hala'ufia.
Bookmark with:
What are these?