Duffy, 26, raced into a 3-0 lead and beat the world number nine easily.
A furious Ding criticised the playing conditions at the York Barbican.
Sheffield's Duffy, who is seeded 121 for the event, said: "I was confident going into the match because I have been working harder than I ever have before, but it's crazy. I am buzzing."
Ding's news conference lasted less than a minute and was littered with swear words.
The Chinese star complained about the table set-up and conditions and will be lucky to escape a fine from World Snooker for his rant.
Three-time UK Championship winner John Higgins had no problems coming through his first-round match.
The 40-year-old Scot, who has already won two ranking events this season, continued his impressive form with a routine 6-1 victory over Leo Fernandez.
Higgins is joined in the second round by three-time runner-up Ken Doherty, Mark Davis, Antony McGill and Sydney Wilson, who came from 4-2 and 5-4 down to stun Welshman Michael White in a thrilling final-frame decider.
Doherty, 46, thumped fellow veteran Tony Drago 6-0, world number 20 Davis beat Rhys Clark 6-1, while Scotland's McGill scored three centuries in a 6-3 victory over James Cahill.
Amateur Adam Duffy pulled off one of the biggest upsets in UK Championship history with a stunning 6-2 win over two-time winner Ding Junhui.