Dunne, who sprang to prominence after sharing the 54-hole lead in the 2015 Open Championship while still an amateur, fired seven birdies and an eagle in a closing 61 to finish 20 under par.
And the 24-year-old sealed victory in style by chipping in on the 18th to finish three shots clear of McIlroy, whose 63 was the lowest score of an injury-plagued season which he will bring to an early, self-imposed end next week.
Sweden’s Robert Karlsson, who began the day with a one-shot lead, finished third on 16 under with Graeme Storm, David Lingmerth and Florian Fritsch on 14 under.
Dunne, who lost a play-off to Edoardo Molinari in the Hassan Trophy in April, enjoyed a remarkable stroke of luck when his approach to the 11th pitched into a sprinkler head on the edge of the green and bounced back to within five feet of the hole.
But the good fortune was well deserved after the 24-year-old played the first six holes in five under par to surge into a lead he would never relinquish, with the victory - worth £500,000 - lifting him into the world’s top 100 for the first time.
“It feels great,” Dunne said. “It’s nice to finally put the demon off my back and get my first win.
“I feel like I’ve been up there a few times this year and never got to put the foot down on Sunday so I woke up this morning determined to really try to win, rather than have someone hand it to me.
“I had a two-shot lead in Morocco and Edoardo finished birdie, eagle so I was just waiting for the leaderboard to show Rory having a hole-in-one on the last or something.”
McIlroy was always playing catch-up despite a hat-trick of birdies from the sixth and his chance of a first win of the year looked to have gone when he missed good chances on the ninth and 10th and bogeyed the next.
However, the four-time major winner refused to throw in the towel and fired five birdies in the next six holes to close within a single shot, but a lengthy birdie attempt on the last was never on line.
That left Dunne needing to par the final two holes for victory but he birdied the 17th and chipped in for another on the last, a fitting end to a week which saw record crowds of 60,180 in attendance.
“It was just nice to have a chance to win a golf tournament and the more chances I have like that the better; I’m more mentally engaged and switched on,” McIlroy said.
“Shooting 64, 63 over the weekend I thought would have had a chance, but that shows how good Paul played. It’s unbelievable to shoot 61 to win his first tour event and I’m happy for him as well. He works hard on his game so it’s very well deserved.
“I don’t feel like I could have done much more but some weeks your best isn’t quite good enough.”
McIlroy will contest the Alfred Dunhill Links Championship with his father Gerry before taking a three-month break to work on his game and regain full fitness following a rib injury.
“I’m looking forward to it,” he added. “My dad rang me a couple of days ago and said he was pleased I’d got my game into shape for him.”
With the win, Dunne moves from 34th to 12th in the Race to Dubai and could move inside the top 90 in the official world ranking from 192nd. He is the 14th first-time winner on the European Tour in 2017, and his score of 126 (-14) over the last two rounds is the lowest closing 36 hole for a first time European Tour win since David Llewellyn in 1987.
Dunne only needed 21 putts on the final day with 7 out of 7 scrambles. His closing 61 equals the lowest finishing round by a winner this season. The last player to shoot a final round of 61 or better to win their first event was Rafa Cabrera Bello at the 2009 Austrian Open