Stoner, who leads the title standings by 35 points from Yamaha's Jorge Lorenzo with five rounds remaining, set his best lap of the afternoon five minutes from the end of the session.
His effort of one minute 48.451 seconds broke his own lap record set just minutes earlier.
The Australian's pole performance also came on his spare bike after he suffered a minor off with just over 10 minutes of the session remaining.
Despite his difficulties, Stoner's efforts were sufficient to see off the challenge of Pedrosa, who posted a best time of 1min 48.747secs but ran off the track on his final lap, blowing any hopes of landing top spot.
Yamaha's Ben Spies suffered an accident in the morning practice session but showed no ill-effects as he claimed the final berth on the front row with a 1:49.155.
The American's team-mate Lorenzo, the winner last time out at Misano, was just a tenth further back in fourth place.
The third Repsol Honda of Andrea Dovizioso claimed fifth, while Marco Simoncelli (Honda Gresini) took the final berth on the outside of row two.
Nicky Hayden (Ducati) took seventh place, with Karel Abraham (Cardion AB Motoracing), Hiroshi Aoyama (Honda Gresini) and Randy De Puniet (Pramac Ducati) completing the top 10.
Britain's Cal Crutchlow was 12th for Tech 3 Yamaha, while Valentino Rossi's miserable maiden campaign with Ducati continued as he suffered a crash early in the session before going on to qualify in 13th place.