World number one Selby will face Barry Hawkins on Friday night for a place in the last four with Ali Carter meeting Michael Holt after his 5-2 victory over Anthony Hamilton at Berlin's Tempodrom.
Shaun Murphy gets the chance to avenge his recent loss to Neil Robertson in the Masters semi-finals when he faces the Australian player after a 5-4 win over fellow former world champion Graeme Dott.
Ding won the opening frame against Selby with a break of 78, but was forced to endure some frustrating times in the next two frames as Selby pocketed both on the final black.
Selby, fresh from his 10-8 win over Neil Robertson that sealed his third Masters success in London, would miss a tricky red to a middle bag holding a 59-1 lead in the second frame, but it was not fatal despite watching Ding close with 35 to force a re-spotted black.
Selby would cut the black from distance before a 33 clearance in the third frame saw him pinch it by six points with Ding missing a red on 55 with the rest that would have sealed the frame.
Selby did not waste too much time in moving 3-1 ahead with a 91 knock before Ding encountered further hardship when he broke down on 60 in failing to sink another red with the rest.
Selby returned to the table to run in 39 and claim his third frame out of five on the final black.
Ding - a double UK champion - showed he was far from dead by punishing Selby for missing a red to a middle hole in the sixth frame as an 87 kept his hopes alive.
His prognosis looked better when a 96 enabled him to close to 4-3 behind, but missing a red to a middle pocket in the penultimate frame ultimately ended his aspirations as Selby concluded his business by clearing to the pink with 48.
Marco Fu meets Matthew Stevens in the quarter-finals after he completed a gritty 5-3 win over Peter Lines with a knock of 80 in the closing frame of the match.
Last 16 results:
Barry Hawkins (Eng) 5-1 Mark Allen (NI)
Neil Robertson (Aus) 5-1 Andrew Higginson (Eng)
Michael Holt (Eng) 5-3 Kurt Maflin (Nor)
Matthew Stevens (Wal) 5-4 Mark King (Eng)
Graeme Dott (Sco) 4-5 Shaun Murphy (Eng)
Peter Lines (Eng) 3-5 Marco Fu (HK)
Ding Junhui (Chn) 3-5 Mark Selby (Eng)
Anthony Hamilton (Eng) 2-5 Ali Carter (Eng)
7pm on Friday
All Carter (Eng) v Michael Holt (Eng)
Neil Robertson (Aus) v Shaun Murphy (Eng)
Marco Fu (HK) v Matthew Stevens (Wal)
Barry Hawkins (Eng) v Mark Selby (Eng)