The Welsh side had appeared to be heading towards a hard-fought victory after John Barclay's try and a conversion and penalty for Aled Thomas had them 10-9 ahead heading into the closing minutes.
But two yellow cards in the last seven minutes for Rob Evans and Mike Poole handed the RaboDirect PRO12 leaders the advantage with O'Mahony touching down late on and JJ Hanrahan added the extras to take his tally to 11 points for the match.
Another team to come from behind and snatch victory late on were Connacht as Dan Parks' late drop goal confirmed a 14-11 win over Newport Gwent Dragons.
A Dan Evans try and two penalties from Jason Tovey had the Dragons 11-6 up with five minutes remaining before Fionn Carr touched down for the hosts to level things up.
Parks had missed the chance to give his side the lead when he missed the conversion but he made no mistake minutes later with his drop goal as Connacht recorded just their second RaboDirect PRO12 victory of the season.
Edinburgh continued their rise up the table as they moved up to sixth with an impressive 11-6 win over Leinster at Murrayfield.
The only try of the game came through Dougie Fife on 31 minutes and it proved the difference as Leinster's Ian Madigan matched the two penalties managed by Edinburgh's returning Greig Laidlaw.
Elsewhere, Ospreys moved up to fourth after Justin Tipuric's try and the boot of Dan Biggar helped them edge the Welsh derby over Cardiff Blues 22-19.
And second-placed Ulster were made the work hard for their 13-6 victory over bottom side Zebre, with Jared Payne's first-half try proving the difference.
While the only other game of round 10 saw Glasgow Warriors' home game with Benetton Treviso postponed because of a waterlogged pitch.
TRY OF THE WEEKEND
They may have had a two-man advantage going into the closing stages of their match with Scarlets, but Munster still had to find a way to cross the whitewash, and it came courtesy of a sublime kick from JJ Hanrahan.
Having failed to find a way past the Scarlets defence on the far side of the field, the ball came out to Hanrahan and the fly-half had the presence of mind to switch the play.
His cross-field kick found Ronan O'Mahony in acres of space, leaving him with the time to ease over for the winning try.
BREAK OF THE WEEKEND
The drama may have come at the end of the match with Dan Parks' late drop goal but there was also a flash of brilliance as early as the eighth minute through Ross Wardle's impressive break.
The Newport Gwent Dragons' wing received the ball on the move, selling a dummy and slicing through the Connacht defence before finding full-back Dan Evans who went over for the try.
Wardle was not done there though, intercepting the ball on his own 22 shortly afterwards and powering forward into Connacht territory.
His pass found Will Harries but Matt Healy pushed the Welshman into touch and the opportunity was gone.
PLAY OF THE WEEKEND
The festive season's first Welsh derby was always going to be a tight affair and with Leigh Halfpenny's kick shortly after the break having got Cardiff Blues to within two points of the Ospreys, Justic Tipuric's try could not have been better timed.
With a line out close to the Blues line, Ospreys seized their chance with a fierce driving maul causing the home defence all sorts of problems.
And with a gap opening up, British & Irish Lion Tipuric dived for the line, and with man-of-the-match Dan Biggar converting, Ospreys suddenly had a nine-point lead on 48 minutes.
PLAYER OF THE WEEKEND
With two penalties in the match, Dan Parks had kept his side in touch heading into the closing stages, and it was then that he really stepped it up.
With the rain lashing down and Connacht peppering the Dragon's defence in the corner, the Scottish international showed skill and composure to send a weighted crosskick to Fion Carr on the opposite side to draw the sides level at 11-11.
Parks would miss the conversion but not one to let it affect him, he defied the wind and rain to send over his drop goal and seal the win for this team.
Follow us on Facebook, join the conversation on Twitter, sign up to our YouTube channel for extensive match highlights and sign up for our newsletter for regular updates on the RaboDirect PRO12