Johnson walked off the final green believing he had won by three strokes after sinking a four-foot par putt, but he ended up being penalized two strokes for not remarking his ball after moving it out of the path of Dufner's putt.
That gave him a double-bogey at the last hole but it was still good enough for 2007 Masters champion Johnson to claim a one-shot win with a 72-hole total of 12-under-par 268 and register his first Tour win since capturing the Colonial two years ago.
Dufner shot a four-over 74 for 269.
Tommy Gainey finished third on 273 after a 67, followed by fellow American Jim Furyk who shot a 68 for 274.
"It was not easy," Johnson said after a round that included four two-shot swings in the final-pairing duel.
"In some respects I kind of feel like I took down a lion. He's been at the top of the game," said Johnson, whose two second-place finishes from his last three events showed he was also in form.
Dufner, winner of the Zurich Classic and Byron Nelson in the last month, had a tough time off the tee, hitting just three of 14 fairways in the final round.
"I had a rough day," said Dufner. "Zach played pretty good. The penalty there made it a little interesting. But I didn't have it today, couldn't keep the ball in the fairway which makes this golf course difficult."
Johnson entered the round one stroke behind Dufner and was tied with him for the lead through 13 holes with the rest of the field well out of the race.
Third place after 54 holes was a distant eight shots off the pace, setting up the head-to-head showdown.
At the ninth, Dufner squandered a two-shot lead with a double bogey after hitting a wedge shot approach into the water.
Johnson suffered a two-stroke swing in the other direction at the 12th after needing two shots to escape a fairway bunker after catching the lip on his first try.
A birdie at the 14th put Johnson ahead for good, and Dufner helped ease the pressure by soaring to a triple-bogey at the 15th after putting his approach shot into the water.
Johnson carried a three-stroke lead to the last, just the right cushion to absorb the stunning final-hole penalty.
"I'm going to focus on the positives because I hit a really solid putt and it's a good thing I made it," an embarrassed Johnson said after the round.
"No harm no foul. I may get a lot of grief for that at home but I got another jacket," he said about the plaid sports coat awarded to the Colonial winner.