O’Sullivan was chasing his third successive world title and sixth of his career.
But Selby , having been 10-5 behind, ran out an 18-14 winner of snooker’s ultimate prize.
He clinched it with an exceptional clearance of the colours, holding his nerve as though it was he who had won this title five times in the past.
Selby punched the air in delight, the new world number one feeling the emotion before laying his hands on the trophy for the first time.
Sheffield Wednesday boss and chairman unhappy after attackers leave for Premier League
Sheffield Wednesday vs Charlton Athletic - All the updates from a sunny Hillsborough afternoon
Sheffield Wednesday ‘obviously huge’ but Charlton Athletic boss makes Owls statement
Sheffield United: Oli Arblaster's brilliant message to fans after making debut for boyhood club
Sheffield United left baffled about key man's injury ahead of big Middlesbrough trip
Selby told BBC2: “(It’s) amazing really.
“It couldn’t be better. You want to win it with Ronnie in the tournament and there’s no better way than playing him in the final.
“I want to thank all my supporters, my wife Vikki and the family and everyone who’s stuck by me.”
Reflecting on his comeback, he added: “I was just my usual self, dug in and never gave in. I didn’t play pretty snooker early in the match but towards the end I played well.
“It was a tough day yesterday. The last two frames were huge. To get back to 10-7 - any other score, I had no chance.”
Having lost the finals of this season’s UK Championship and World Open, Selby was relieved to find his form on the big occasion this time around.
“I was sort of half-dreading coming to the World Championship because my form wasn’t great,” he said.
“I got back from China, I didn’t play that well out there, and I just put in the hard work. Something seemed to click, and I came here confident.”
O’Sullivan said: “I just want to congratulate Mark on a fantastic tournament.
“He’s been the best player these last 17 days and had another good season.”
O’Sullivan missed a simple pink in the final frame of Monday afternoon’s session which would have taken him 12-11 up, but he said: “The black last night at 10-5 was the more important one.
“If we’d both been going hammer and tongs, a ball like that (pink) could have been a turning point but it was more about safety at that point.
“He just outfought me, outbattled me. It was tough. He had me in all sorts of trouble for two days. I tried my best but he was too tough and he’s a worthy champion.
“Four or five years ago I would have freaked out in that match but I never gave up. I’m sorry for not giving the performance but I tried my hardest.”
O’Sullivan had won 14 matches in a row at the Crucible, taking the 2012 and 2013 titles and charging to his sixth final this year.
But where he had won each of those previous five finals, in Selby he struck upon an opponent who believed he could succeed where John Higgins, Graeme Dott, Ali Carter - twice - and Barry Hawkins all fell short.
And even when his hopes looked forlorn, Selby stuck at his task, crucially winning the final two frames on Sunday night to cut his arrears to three.
Selby had lost in the finals of the UK Championship and Masters already this season, so a hat-trick of such defeats in the tournaments that make up snooker’s triple crown would have been tough to bear.
In the opening 11 frames, his highest break was a mere 42, and until he reaped a total clearance of 127 in the 30th frame his best was 74, contrasting with O’Sullivan’s three centuries.
The new champion was chiselling out chances but needing two, three or four to win frames, but it was telling that O’Sullivan was presenting him with the openings. It was far from a classic O’Sullivan performance, with the 38-year-old looking deflated a long time before Selby passed the winning post.
In his recent book, O’Sullivan branded Selby a snooker ‘torturer’, and the drip, drip, drip of pressure, hard match play, and pedestrian pace added up to agony for a man with a history of struggling when such factors are pieced together by a high-class opponent.
O’Sullivan began the evening with a seven-minute century to get back to 12-12, but Selby soon restored his advantage, and the scrappier the frames became, the more the pre-match underdog appeared to have the edge.
He added the next to lead 14-12 - two frames ahead for the first time - and it meant he had taken nine of the last 11, having trailed 9-5 at one stage on Sunday.
And when a run of 56 nudged Selby three clear at the interval, he was just a further three from the winning line.
O’Sullivan cut his arrears with a solid response, including a break of 49, and made it 15-14 after a terrific run of 37 at the business end of the next frame, its highlight being a stunning long yellow.
It was Selby’s turn to show the reaction of a champion, and his first century of the match showed he was not merely coping but thriving under the pressure.
He was two away, and on the brink after the next frame when he fired in 87 to lead 17-14.
He clinched it in style, the final piece in the jigsaw of his career secured for a man with multiple titles elsewhere, including UK Championship and Masters crowns.