Trailing 25-23 with five minutes of additional time already on the clock, Flanagan took one final roll of the dice saw his effort sail through the posts. It was enough to clinch Pontypridd's third Welsh Cup title and at the same time deny Neath an historic double after winning the Principality Premiership last week.
It was so nearly a different story however after Paul Jones crashed over and then Flanagan saw his pass intercepted by opposite number James Hook who ran it back for a try and added the conversion to cap a stunning comeback. Pontypridd had led 23-13 through tries from Matthew Nuthall, Dafydd Lockyer and Chris Clayton.
The opening try from Nuthall was worth waiting for as he rounded Gareth Morris after a scorching 50-yard run after 23 minutes. Somehow Neath found a way back to lead 13-11 at the break. Flanker Andy Llewellyn went over after Stephen Thomas's scoring pass and Hook added the conversion and a late penalty.
Ponty came roaring back after the break and scored inside two minutes when scrum-half Gareth Jones sent Lockyer galloping down the left-hand touchline to score, and they looked to have wrapped it up when Tom Riley stole possession in midfield and prop Scott Roberts sent Clayton over to open a ten-point lead.
Wales U21 lock Chris Dicomidis was yellow carded and Neath's Paul Jones shoved his way over before Hook intercepted Flanagan's pass to score under the posts only for Flanagan to reply in style.
Tries - A Llewellyn, P Jones, J Hook
Cons - J Hook (2)
Pens - J Hook (2)
Tries - M Nuthall, D Lockyer, C Clayton
Con - D Flanagan
Pens - D Flanagan (2)
Drop G - D Flanagan
Referee: Nigel Owens (WRU)