The factory test rider went one better than his Mugello qualifying as he used the soft rear tyre to lap 0.590s from Yamaha pole sitter Jorge Lorenzo.
"I am very pleased because we have always been in amongst the top positions throughout the entire weekend and a row two start from fifth place is a fantastic result," Pirro said.
"It wasn't easy to achieve, even though I believed I could do it, and above all merit must go to the team, who did an incredible job.
"I want to thank Claudio Domenicali, Gigi Dall'Igna and everyone who made possible my presence here as wild-card, giving me the opportunity to show how quick I am."
Pirro will now aim to beat the eighth place achieved at Mugello this year.
Ducati team regulars Andrea Iannone and Andrea Dovizioso will start seventh (+0.675s) and eighth (+0.788s) respectiv ely.
"I'm disappointed with my laps in qualifying," said Dovizioso. "Starting from the second row is quite important at this track. But in Free Practice 4 our pace improved, we are not so far, and now it will be very important to start with the first three or four riders."
Iannone added: ""I'm happy because I improved a lot compared with yesterday. This is really important. But in FP3 I have a problem with the bike and it was impossible to continue with the first bike. For our work in practice this was not the best.
"But ok, I arrived in FP4 with a good setting and good feeling with the bike. My lap time is not so bad. Constant, constant. I'm happy for this. So I have only one disappointment for today, the qualifying. The soft tyre was a little bit difficult for me. The lap time was not so fast, but I'll try my best for the race and I have a good feeling with the bike."