"It was an awesome race. It's a great way to do it when the gloves are off and it's bare-knuckle fighting," Johnson said. "I got a great restart and got by him. I knew we had the speed if I could just get by him."
Keselowski had taken only left-side tires when everybody else took four tires and went from fourth to first on another restart with 19 laps left. But there were two more restarts after that, including one when Johnson and Keselowski banged together hard after they got going, but Johnson won the one that counted most.
"Man, I thought I had it, but we kept getting all those yellows," Keselowski said. "I knew I wasn't going to be able to execute every restart, and Jimmie did a great job on that last one."
Johnson increased the No. 48 Chevrolet's lead by five points to seven over Keselowski, a runner-up in his No. 2 Dodge at Texas by leading 75 laps after never before finishing better than 14th.
They go to Phoenix next week, where Johnson was fourth and Keselowski fifth in the second race of the season eight months ago. The season finale is at Homestead.
Kyle Busch, who led four times for 80 laps, finished third and Matt Kenseth was fourth.
It was Johnson's 60th career victory and second at Texas, where he was the runner-up in April. It also was the 700th NASCAR Sprint Cup victory for Chevy.
Johnson's teammates Jeff Gordon and Kasey Kahne were involved in contact in the back of the field with Greg Biffle, setting up a restart with eight laps to go.
After Johnson charged high, and got a little loose, he came to the line side-by-side with Keselowski.
On the next lap, they made hard contact but kept going forward. Johnson maintained a slight lead at the line, but Keselowski pulled ahead and was still in front for two laps before Mark Martin spun out on the front stretch, setting up the final green-white-checkered finish.
There were nine cautions for 49 laps, including that late flurry that changed the race. It sure didn't start that way, but then there were some yellow flags in bunches.
Keselowski had more than a 2-second lead over Johnson when there was a caution for debris with 59 laps left.
But Keselowski got in his pit box awkwardly, then had to back up to get around Danica Patrick's car in the stall ahead of him. Once Keselowski pulled out, he ended up in a jam of cars and dropped eight spots to ninth for the restart.
Keselowski worked himself back up to fourth before the next stop, when he took two tires and went back in front.
After the April race at Texas ended with a track-record 234 consecutive green-flag laps, the first 100 laps Sunday were without a caution. That 334 laps was the equivalent of 501 miles, or a full Sprint Cup race at Texas. The first caution was caused by debris on the track, and there were two more cautions within a span of 20 laps after that.
Sprint Cup standings
1. Johnson 2,339
2. Keselowski 2,332 -7
3. Bowyer 2,203 -36
4. Kahne 2,281 -58
5. Kenseth 2,267 -72
5. Gordon 2,267 -72
7. Hamlin 2,266 -73
8. Stewart 2,259 -80
8. Truex 2,259 -80
10. Biffle 2,256 -83
11. Harvick 2,238 -101
12. Earnhardt 2,188 -151