Hamlin turned a lap at 99.595 mph around the 0.526-mile oval, the oldest and shortest in the Sprint Cup Series. It's his 17th career pole, third at Martinsville and career-best fifth this season.
"I knew we were going to be pretty strong," Hamlin said about the track where he's won four times. "I knew we had a shot at the pole and, beyond that, I think our car is pretty good in race trim as well."
Hamlin later also won the pole for Saturday's truck race, where he'll seek his third straight victory at the track.
Johnson, a five-time champion for Hendrick Motorsports, will start the race with a four-point lead over Matt Kenseth in the championship, and surrounded by Kenseth and his teammates—Hamlin and Kyle Busch.
"No," Johnson said when asked if being surrounded made him nervous. "Maybe I should be, but not as of now. We will all race hard I'm sure. We have all been, at least so far, have been a lot of situations with each driver and been able to race hard and take it right to the line, but not cross it."
Johnson and Busch actually tied in qualifying at 99.344 mph, but Johnson was awarded the second spot based on the owner points tiebreaker, moving Busch to the third spot with Kenseth alongside.
Johnson, who has won eight times at Martinsville, including the last two, said his team struggled for much of the day in practice, but "we found some direction there at the end and made some adjustments."
The top 10 in the starting grid features half of the top 10 in points with just four events to go. Busch and Kevin Harvick (starting 10th) are third, 26 back, and Jeff Gordon (9th) is fifth, 34 back.
Hamlin, who is in danger of seeing his streak of seasons with a victory end at seven if he can't claim one of the final races, said he will race hard for at victory, and to be a good teammate.
"I think both my teammates and the guys who are around will know that I'm racing for a race win and that's it," Hamlin said. "I'll take more risks, obviously, when racing for a win. I will be a lot more aggressive with a non-teammate than I will with a teammate, so that part of it is a little bit different, but that would be the only way I don't givbe 100 percent racing for a win."