During the middle portions of the race, Matt Kenseth and Kyle Busch were faster than Johnson. And with 75 laps to go, it was obvious that Jeff Gordon had the fastest car and was running down Johnson.
But as crew chief Chad Knaus told Johnson over the radio with 52 laps to go, "the 24 (Gordon) is faster than us, but with a small little adjustment, we will be OK."
And how right Knaus was as Johnson was the strongest in the deciding stages of the race as he held off Clint Bowyer and Gordon to win his second race of 2013, his second straight at Martinsville and his eighth at the flat, half-mile track.
The victory, the 62nd of Johnson's career, vaulted him back into the point lead as he seeks his sixth championship.
Only Richard Petty with 15 wins and Darrell Waltrip with 11 victories has won more times than Johnson at Martinsville, the only track still on the schedule from the sport's first year of existence -- 1949.
"For a long time, I thought Matt Kenseth was going to win this race," said Johnson, "and he doesn't like this place. But we made the right changes at the end, and we were at our best when it counted."
Kasey Kahne finished fourth with Kyle Busch edging Brad Keselowski by inches for fifth in a side-by-side duel on the final lap.
Completing the top 10 were Jamie McMurray, Marcos Ambrose, Greg Biffle and Mark Martin, subbing for the injured Denny Hamlin.
Danica Patrick, in her first race at one of the toughest race tracks on the NASCAR Sprint Cup Series, finished a surprising 12th after losing a last-lap, three-wide battle with Brian Vickers and Kevin Harvick.
Patrick brought out the first yellow flag on lap 70 when she tried to pass Ken Schrader and Schrader cut her off and she spun out to keep from hitting him.
Later, she fell two laps down. But twice she used the wave around to get a lap back and once she got back on the lead lap, she became very aggressive and passed a lot of the top drivers including her boss Tony Stewart and former points leader Dale Earnhardt.
With only 35 laps left in the race, she was trying to pass Earnhardt again when she was hit from behind by Vickers, which turned her into Earnhardt with Earnhardt spinning to bring out the 11th yellow flag of the day.
Bowyer had just passed Gordon for second when the caution came out.
For the rest of the race, Johnson was able to win every restart as he ended up leading six times for a race-high 346 laps, including the final 138.
Kenseth, who led three times for 96 laps, ended up 14th when he decided to gamble on a four-tire pit stop with eight laps to go. The move backfired as Kenseth was not able to get back to the top six where he was running when he pitted.
"We knew we couldn't win the race the way the car was, so we decided to gamble on new tires," Kenseth said. "We just didn't have enough time to get back up there. For a long time, we had the best car. But at the end, we weren't as good as before and the 48 (Johnson), the 15 (Bowyer) and the 24 were better than we were.
"But that's the best we've even ran at Martinsville and the best car I've ever had here by far. We just didn't get the finish we wanted, which is disappointing."
The final caution came out when Kurt Busch lost his brakes and crashed hard into the fourth-turn wall with his car catching on fire. Busch was able to hit the fire extinguisher nozzle inside his car to put out the blaze just moments before he climbed out of the battered car. Busch was unhurt.
The race was red-flagged for almost six-and-a-half minutes as track officials cleared up the speedway.
When the green was waved for the final time, there were only eight laps to go and Johnson quickly got the jump on Bowyer with Johnson beating Bowyer to the finish line by six-tenths of a second.
For Hendrick Motorsports, it was the 20th win for the organization at the track.
"I thought it was going to be a Jeff Gordon day," said Johnson of his Hendrick teammate, "as he is always really strong here on longer runs and he was really coming (with 75 laps to go). But when the caution came out (on lap 449), I knew it (the edge) had switched back to me," said Johnson.
"I have just learned that there are a lot of short runs at the end here, and I have learned how to handle that. And I thought we were the best on short runs and Chad made the right adjustment on that last stop.
"I felt at the end that if I was able to get ahead of Clint by the third corner (on the final restart), I would be able to get away from him. I have just learned how to get the most out of old tires for the short runs."