The Italian, who goes into the final weekend of the season 24 points behind championship leader Jorge Martin, did all he could to lay the pressure on the Spaniard who will start on the second row in fourth, AFP wrote.
“I’m very happy,” said Ducati-Lenovo rider Bagnaia. “We managed to do a very good job. It wasn’t easy because the conditions were very tricky and a bit risky but everything went well.”
Bagnaia clocked one minute and 38.641 seconds, just 0.055sec ahead of Aprilia’s Aleix Espargaro, taking part in his 255th and final race before retiring.
Marc Marquez, of the Ducati satellite team Gresini, was third quickest, nudging Martin off the front row.
The race was due to take place in Valencia but had to be moved after the region suffered its worst floods in a generation which have killed more than 220 people.
The race was switched to the Circuit de Barcelona-Catalunya and has been dubbed the Solidarity GP to show support for the people of Valencia.