Johnson, out for over two months with back trouble, birdied two of the last three holes for a closing 66 and a one-stroke victory over compatriot John Merrick, who almost chipped in to force a play-off.
McIlroy, who starts his defence of the US Open on Thursday, had gone two ahead with birdies at the second, fourth, seventh and short 11th, where he almost sank his tee shot, but he drove into the water on the next and bogeyed the 14th as well by three-putting from 32 feet.
A 20-footer for birdie on the 17th made him joint leader again, but just as Johnson was matching that to nose in front the Northern Irishman drove into more water off the last tee and with a double bogey six he dropped into a tie for seventh place.
It was still a massive improvement on his last three tournaments - all missed cuts - and the 23-year-old world number two will draw the positives from that as he heads to San Francisco.
Watch: Johnson wins St. Jude Classic.. More Videos