The Northern Irishman started six shots behind overnight leader Paul Casey, but seven birdies in a six-under-par 65 saw him finish two shots clear at 15 under.
England's Casey, 39, missed an eagle putt on the final hole at TPC Boston that would have forced a play-off.
It was 27-year-old McIlroy's first tournament win since the Irish Open in May and first PGA title since May 2015.
The victory comes just a week after he changed his putter and his putting coach.
He told Sky Sports: "I played some great golf and holed some great putts. I'm just really proud of myself, how I hung in there on the first day and then got some momentum on Saturday. Then I just went with it.
"It's nice to get that first win in the States this year and hopefully I can take this momentum into the next couple of weeks and ultimately the Ryder Cup."
The Deutsche Bank Championship is the second of the four that make up the season-ending FedEx Cup.
McIlroy will rise 34 places to fourth in the FedEx Cup standings - and nearer the $10m (£7.52m) prize for the winner - as a result of his victory.