A crucial moment came at 15-11 to Selby when he overran his shot on the pink to give himself a tricky position on the black at 60-60 in the frame.
But with Ding looking on in hope, sensing a chance to claw his way back into the contest again, Selby cut the black into the pocket brilliantly to put himself within two frames of glory.
Ding responded magnificently, though, rattling in the next three frames to move to within two frames of Selby, in a match which was becoming something of a classic. Ding’s 103 break to make it 16-14 was the 86th of the tournament – equaling last year’s record.
But Selby saw out the match, just minutes after his beloved Leicester City had won the Premier League.
Selby notches up another century with 126 clearance
Selby punched his fist in delight after scrambling over the line in the 17th and final frame of Sunday's prolonged play, which included an epic 15th frame that lasted an astonishing 66 minutes, relieved to protect a lead that was in danger of collapse as Ding mounted a spirited recovery.
Qualifier Ding - the first man from Asia to contest a world final - seemed suffocated by nerves after trailing 6-0 early on.
But he won the final two frames of the afternoon session before picking up five of the next seven to trail by one.
Mark Selby celebrates winning a vital 17th frame
Selby steeled himself for another push in the final two frames of the session. Despite being visibly tired, the world number one fell over the line to leave himself eight frames short of winning a second world title on Monday.
It is the first time Selby has carried an overnight lead into the final day of the tournament having trailed John Higgins 12-4 in 2007 and Ronnie O'Sullivan 10-7 two years ago.
Ding will be heartened by his effort, and still has a strong chance to make history with 100m fans watching on TV in China and willing him to make history back in his homeland.
Selby extended his lead with the first frame of the second session, though Ding returned the deficit to four frames when he won the second with a break of 76.
A lovely 103 gave Ding the third frame, and he snatched the fourth frame before the mid-session interval after a safety joust. Ding was the victor, and moved within two frames of his opponent.
Selby moved 8-5 clear with his first frame after the interval. The next frame was a re-rack, and Ding again cut the lead to two frames, but the nearest he got was to within one frame before Selby's late surge provided him with a sense of comfort heading for his night's sleep.
Mark Selby took a comfortable 6-2 lead at the end of the first session of the World Snooker Championships final.
Selby started the first session brightly. He seized on an error from Ding to make a break of 91. It appeared that Ding would level with the second frame, but Selby, requiring snookers, snatched it to move into a 2-0 lead.
Mark Selby wraps up opening frame with quality clearance of 91
Ding appeared to have won his first frame as he started brightly in the third, only for Selby to hit back. Ding tried to force a win with some attempted snookers, but he couldn’t win enough points and ultimately conceded the frame. A century break from Selby moved him onto a 4-0 lead before the mid-session interval.
Selby eased into a 6-0 lead before a scrappy, drawn-out seventh frame was won by Ding for his first frame of the match, and fought his way to a 6-2 scoreline, giving him fresh hope for the second session.
Mark Selby opens up four-frame lead with break of 120