O'Sullivan - who played with a broken ankle after injuring himself out jogging prior to snooker's second biggest ranking tournament - led 5-1 and 9-4, but was forced to contest a final-frame decider as Trump produced some immaculate snooker to win five frames on the trot.
O'Sullivan, who turned 39 during a tournament he first won at the age of 17 in 1993, did little or nothing wrong in losing five successive frames, but held himself superbly well to dominate the deciding frame.
O'Sullivan has enjoyed an outstanding 2014 adding the UK title to the Masters, Welsh Open and Champion of Champions trophies. His only frustration was blowing a 10-5 lead over Mark Selby in losing the World Championship 18-14 that would have given him a sixth victory at the Crucible Theatre in Sheffield.
'So upset' – Saengkham fights back from Covid-19 misery to stun Higgins
He draws level with Stephen Hendry on five UK titles with Steve Davis remaining one clear on six.
It was little wonder he was left punching the air after edging out Trump, 25, who himself landed the UK title three years ago.
"I was just gone," said Masters champion O'Sullivan, who collected £150,000 for lifting the trophy and £44,000 for compiling his 13th 147 maximum break against Matthew Selt in the last 16.
"I found something towards the end. That was the hardest match I've ever played. It was tough to hold my head together. I probably thought he was going to win."
Resuming 5-3 aided by runs of 82 and 81, the five-times world champion won four of the next five frames as breaks of 53, 133 and 54 carried him to the cusp of victory.
Trump appeared down and out, but suddenly produced his very best snooker as knocks of 42, 120, 127 and 86 saw him move to within one frame of the game's greatest player.
O'Sullivan appeared to have stemmed the tide in frame 18, but he broke down holding a 59-0 lead, and was foced to sit and suffer as Bristolian Trump - the 2011 World Championship finalist - compiled 69 to restore parity at 9-9.
With tension palpable in the Barbican Centre, both men had chances but a telling snooker behind the green prompted the key mistake by Trump that enabled O'Sullivan to compile a winning run of 51 as Trump's rousing recovery came up agonisingly short.
'Embarrassed himself' – Watch funny moment Vahedi messes up break-off shot
'I don't like maximums' – Doherty shows timeless class despite missing 147 chance