"I raced hard, and I'm sure someone would say dirty," Keselowski said. "But I raced hard and we both came back around, so there's something to be said for that."
It was Johnson's 60th career victory and second at Texas, where he was the runner-up in April. It was also the 700th NASCAR Sprint Cup victory for Chevy, and means a huge donation for disaster relief efforts on the East Coast in the wake of Superstorm Sandy.
Johnson's primary Hendrick Motorsports sponsor Lowe's pledged to match what he earned at Texas. The winning share of the $7 million purse was $492,086.
Kyle Busch, who led four times for 80 laps, finished third and Matt Kenseth was fourth.
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 and pulled out into a big jam of cars.
Keselowski worked himself back up to fourth before the next stop, when he took two tires.
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.
During that first stop, Keselowski also took only two tires and within two laps led his first lap to get a bonus point after passing Ryan Newman, who hadn't pitted. That was a short-lived lead before AJ Allmendinger spun out of control out of Turn 4 into the infield.
Keselowski and Johnson re-started side-by-side and in the one green-flag lap that was completed before another caution, Johnson edged back in front.
It had been a smooth Sunday drive for Johnson before all those interruptions.
Johnson charged ahead, and was quickly a few car lengths in front of the field. Within three laps after the first pit stop, he cycled back into the lead with Keselowski four spots and 5.3 seconds behind.
Following the second set of green-flag stops, Johnson and Keselowski were 1-2, but there was a nearly 4-second gap between them.
Tony Stewart finished fifth, followed by Clint Bowyer, who is now 36 points back in third in the series standings.