Despite shooting a three-over 75 on Sunday, the 25-year-old did just enough to hang on and finish three shots ahead of American Ryan Palmer.
Rahm had a four-stroke lead heading into the final round, and it appeared through the front nine that he was cruising to his fourth PGA Tour victory.
However, a bogey on the 10th signalled a change of momentum, and Rahm suffered a double bogey on the 11th before losing another stroke on the 14th.
The biggest moment of the day came on the par-three 16th, when an up-and-down birdie was overturned when PGA Tour officials reviewed the chip and deemed the ball slightly moved when Rahm placed his wedge behind it.
Despite receiving a two-stroke penalty, with challengers failing to take advantage of his stumbles, back-to-back pars on the final two holes ensured Rahm stayed clear of Palmer at the top of the leaderboard.
"I stay on competition mode for a little longer than I would like sometimes, and I process things so much later. I'll probably wake up tomorrow morning and still not have it processed," Rahm told reporters.
"I'm incredibly proud to sit here and be the Memorial tournament champion, win an event on the PGA Tour four years in a row, number one in the world.
"There's a lot of accomplishments today that are hard to believe I've done so early in my career."
The best performer of the day was England's Matthew Fitzpatrick, whose four-under 68 secured third place.
Fellow Briton Matt Wallace finished close behind in fourth place after shooting an even 72.
Meanwhile McIlroy, who was well off the pace headed into Sunday's final round, saved his worst for last.
The Northern Irishman picked up five bogeys and a double bogey as he ended the day six-over par and finished the tournament tied for 32nd.
He had been at the top of the world golf rankings since February 9, however he is yet to record a top 10 finish following the resumption of the tour.