Tipperary's Liam Casey emerged as UCD's last action hero at Santry Avenue where the Electric Ireland Sigerson Cup final favourites eventually edged an epic encounter.
Maurice Sheridan's NUI Galway led by two points with 10 minutes to go and looked well positioned to push on for a first title success in 15 years.
But a UCD side containing Dublin All-Star Con O'Callaghan and Monaghan's Conor McCarthy, who was Man of the Match with 1-6, finished strongest and crucially outscored NUI Galway by 0-4 to 0-1 in the run in.
Dual star O'Callaghan scored the first of those four late UCD points and McCarthy the next though it was Casey's back to back points that ultimately secured their 34th Sigerson.
It was UCD's third final in a row though they lost out to St Mary's last year having previously claimed the title in 2016 when they beat DCU.
They were fancied for the win here but were made to fight all the way and were hugely fortunate that NUI Galway captain Damien Comer struck the woodwork with a palmed effort in the 20th minute.
A goal at that stage for NUI Galway would have left them 1-5 to 0-1 but, instead of trailing by that seven-point margin, UCD went down the other end and netted themselves through McCarthy, leaving just a point in it.
It was a giant reprieve for UCD though the game still went all the way to the wire with extra-time looming throughout the final quarter in a tense decider.
Former Mayo player Sheridan was in charge of NUI Galway who were aided by Kieran Molloy who dashed from Tullamore, where he'd played for Corofin in the AIB All-Ireland club semi-finals, to come on as a second-half substitute.
Molloy was involved in two important plays, helping Adam Gallagher to score a goal in the 49th minute and he also surged upfield to strike a shot off an upright.
A second Corofin player, Liam Silke, is part of the UCD setup but picked up an injury in the Corofin game and wasn't going to be used by Divilly anyhow.
McCarthy hit UCD's first 1-3 and further points from Laois duo Eoin Lowry and Evan O'Carroll tied the scores up at half-time, 1-5 to 0-8.
Casey opened the second-half scoring for UCD but NUI Galway netted through Sean Kelly in the 39th minute when he flicked home after Comer's shot was only half cleared.
UCD fought back to lead briefly at 1-9 to 1-8 but then Molloy and Eoin Finnerty combined to play in Gallagher for NUI Galway's second goal.
That left Sheridan's side 2-8 to 1-9 up with 10 minutes of normal time to go.
But UCD finished strongest and reeled in that two-point deficit by outscoring their opponents 0-4 to 0-1 in the closing minutes. Casey was their hero and not even a black card in the closing moments could dampen the Cahir man's joy.
Conor McCarthy 1-6 (0-3f), Liam Casey 0-3, Eoin Lowry 0-2, Evan O'Carroll 0-1, Con O'Callaghan 0-1
Adam Gallagher 1-3 (0-3f), Sean Kelly 1-0, Damien Comer 0-3, Enda Tierney 0-3 (0-1f),
Charlie Manton (Tipperary); Peter Healy (Antroim), Cillian O'Shea (Dublin), Conor Mullally (Dublin); Luke Fortune (Cavan), Jimmy Feehan (Tipperary), Stephen Coen (Mayo); Barry O'Sullivan (Kerry), Jack Barry (Kerry); Liam Casey (Tipperary), Conor McCarthy (Monaghan), Brian Byrne (Kildare); Eoin Lowry (Laois), Evan O'Carroll (Laois), Con O'Callaghan (Dublin).
Brian O'Seanachain (Kerry) for Fortune (h/t), Tom Hayes for O'Carroll (58).
Tadhg O'Malley (Galway); Kevin McDonnell (Sligo), Sean Mulkerrin (Galway), Stephen Brennan (Mayo); Gerard O'Kelly-Lynch (Sligo), Ruairi Greene (Galway), Colm Kelly (Donegal); Cein D'Arcy (Galway), Peter Cooke (Galway); Enda Tierney (Galway), Owen Gallagher (Antrim), Adam Gallagher (Mayo); Sean Kelly (Galway), Damien Comer (Galway), Brian Donovan (Limerick).
Ronan O'Toole (Westmeath) for Kelly (34), Kieran Molloy (Galway) for Greene (39), Eoin Finnerty (Galway) for Owen Gallagher (44), Ryan Forde (Galway) for Donovan (46).
Joe McQuillan (Cavan).