Breaks of 71 and 77 put Ding 2-1 up before a 66 from McGill levelled matters.
After the Glaswegian made 49 in frame five Ding came back to clinch it with a 40 clearance.
McGill, 21, missed a tricky yellow in the next frame and would not play another shot in his maiden professional final as Ding recorded a break of 71 to seal a first tournament victory since last season's Welsh Open.
"I played well this week, I made a lot of big breaks and concentrated in every game," said Ding. "I was a bit lucky tonight, the fifth frame was a big one.
"I've built a lot of confidence here and if I can keep my form going I can win more titles this season."
Earlier on Sunday he knocked six-times world champion Steve Davis out in the last 16 before disposing of Ian Burns then Ken Doherty.
McGill, meanwhile, beat Nigel Bond before 4-3 triumphs over Thanawat Tirapongpaiboon and Andrew Higginson.
He was 3-0 down in his quarter-final against the Thai and 3-1 behind against Higginson before coming back to win on a respotted black in the decider.
"I could have been out earlier, to get to the final is a personal best," McGill said. "But I missed too many easy pots in the end. It was my first time in a big arena and I'll deal with it better next time."
The Scottish Open served as event five in the Players Tour Championship, with the Munich Open on January 4-6 the next event in that series.
Thanawat Tirapongpaiboon 4-3 Barry Hawkins
Nigel Bond 1-4 Anthony McGill
Jimmy Robertson 1-4 Andrew Higginson
Kurt Maflin 3-4 Martin O'Donnell
Steve Davis 1-4 Ding Junhui
Ian Burns 4-2 Liang Wenbo
Mark Joyce 4-3 Gary Wilson
Ken Doherty 4-2 Ryan Day
Thanawat Tirapongpaiboon 3-4 Anthony McGill
Andrew Higginson 4-2 Martin O'Donnell
Ding Junhui 4-1 Ian Burns
Mark Joyce 2-4 Ken Doherty
Anthony McGill 4-3 Andrew Higginson
Ding Junhui 4-2 Ken Doherty
Anthony McGill 2-4 Ding Junhui