Allen looked down and out after falling 6-1 behind against the resurgent Chinese star but stormed back to pocket the £250,000 winner's cheque and become the first Northern Irishman to win the prestigious crown since Alex Higgins in 1983.
It completed a remarkable tournament for the 36-year-old who had also fought from at least two frames down in each of his previous matches in the tournament, including winning the last three to beat Jack Lisowski 6-5 in their semi-final.
"I don't really know how I've done it - I didn't play very well most of the week and I struggled from the start and Ding punished me heavily, and I just scraped the last frame (of the session)," said Allen.
"I don't know what happened tonight. The first frame was as good a break as I'd made all day and all of a sudden I felt so good.
"I was struggling but I was trying to stay as positive as possible in my seat, which is something I've been working really hard on. I just kept saying myself can I win the next frame, and my answer was always yes."
Ding had looked odds-on for a fourth UK title of his career after firing three centuries in a glittering afternoon session as he looked to become the first qualifier to win since he claimed his maiden title in 2005.
Ding, who handed Ronnie O'Sullivan his first major whitewash earlier in the tournament, was in irresistible form with breaks of 126 and 135 either side of the mid-session interval then a knock of 102 to move five frames in front.
Allen gave himself a flicker of hope when he capitalised on a missed red by Ding in the final frame of the afternoon session to compile a frame-winning 79 - and after Ding broke down on a break of 33 in the next the momentum swung in the direction of the Antrim man.
Ding did not pot another ball for an hour as Allen stormed back with a break of 63 to reduce the deficit to 6-3, before back-to-back knocks of 93 and 132 took him back within one frame of his opponent.
Allen, whose previous career high point was winning the 2018 Masters, took control of the next with a break of 56 and despite a battling comeback from Ding, a missed green eventually let the Northern Irishman pull level at 6-6 at the mid-session interval.
Allen went ahead for the first time in the match after a break of 59 set him up to clinch a gruelling 13th frame, and was merciless again in the next when he fired his second century, a 109, to move two frames from completing a remarkable turnaround.
Ding punched the table in frustration after running out of position in the next but proceeded to spectacularly stop the rot with a break of 105, his fourth century of the match, to reduce the deficit to 8-7.
A nerveless red to the middle set up a break of 42 from which Allen was able to build to within one frame of victory, and he held his nerve in a 17th that stretched to almost an hour, clenching his fists after sinking the match-winning pink.
"To follow in Alex's footsteps is obviously a great achievement," added Allen. "But I'm trying to create my own legacy in this game and I'm a long way from that yet."