Stewart waited right until the end of the final round to attempt his lap and circled the speedway at 195.454 mph to grab the top starting spot for Sunday's race.
It's Stewart's 15th career pole and first since Atlanta in 2012.
"It was cool. I'm not normally a qualifier," Stewart said.
Keselowski made his attempt earlier in the session and turned his lap at 195.419. He was out of his car and watching the scoring pylon as Stewart crossed the finish line, and Keselowski dropped his head in disappointment when he saw he'd been beaten.
"Stewart put down a great lap at the end, didn't see that one coming," Keselowski said. "That's why they do it this way. Really exciting and a lot of fun to watch, and quite honestly, a lot of fun to participate in this new format of qualifying."
Kevin Harvick qualified third as two Stewart-Haas Racing Chevrolets were in the top three. The organization is the only one in the Sprint Cup Series with two wins this season — Harvick won at Phoenix and Kurt Busch won last week at Martinsville — but the four cars have been all over the map and lacked consistency.
"Tony capturing the pole is as good as it gets for the organization," Harvick said. "That's a huge improvement for where we've been as a company the last few weeks."
Busch qualified 11th as three of the four SHR drivers advanced into the third and final round of knockout qualifying.
The final session was dominated by Fords as blue oval drivers claimed six of the final 12 spots and were led by Keselowski, who will start on the front row for the fifth time in seven races this season.
Ford drivers Greg Biffle and Carl Edwards qualified fourth and fifth for Roush Fenway Racing.
Then came Joe Gibbs Racing's Denny Hamlin, the only Toyota driver to make it to the top 12.
Trevor Bayne was seventh in his first appearance in the final group this season, and he was followed by Ryan Newman, Marcos Ambrose, Joey Logano, Busch and Jeff Gordon.
Six-time NASCAR champion Jimmie Johnson failed to advance to the final round for the first time this season.
"We're really surprised not to have pace here in qualifying," Johnson said. "We have a very fast race car, in race trim especially. Our car is blazing fast. Qualifying hasn't always been my strong suit, and today it showed up here for whatever reason.
"We'll get her cleaned up and get her ready for the race on Sunday."