Pedrosa eventually eased to victory ahead of Katsuyuki Nakasuga and Stoner, who passed Alvaro Bautista with two laps remaining.
Briton Cal Crutchlow crashed out from a calm situation in second, around half a minute behind Pedrosa and the same ahead of Nakasuga, with seven laps remaining.
The race was officially declared wet. Almost every rider opted for wet tyres, with Lorenzo a notable exception on slicks.
The tarmac had taken a long time to dry, according to Stoner on the grid, but several riders - Repsol Honda's pole sitter Pedrosa among them - had a change of heart on the warm-up lap and opted to start from the pitlane and change to bikes with slicks.
Stoner also said that he "didn't really want to be here... these are not the conditions I wanted to end my career in. It is one of the worst I have ever seen". He would ride his Repsol Honda cautiously for most of the race as chaos flared the length of the track, before pushing hard to catch Gresini Honda's Bautista in the final laps.
Yamaha test rider Nakasuga - riding as Lorenzo's team-mate, with Ben Spies ruled out with a shoulder injury - went with slicks at the start and was vindicated. However the tale did not end as well for Lorenzo.
Having dropped to sixth from first at the start - although he started on the second grid spot - as Aleix Espargaro blasted through to take the lead from 10th, he steadily clawed his way through the field and led by the fifth lap as Stoner and Andrea Dovizioso came in for slick bikes.
By lap 10, however, Pedrosa was the faster rider and right up behind his Spanish compatriot, promising an intriguing battle at the front.
But it was not to be as Lorenzo wobbled the Yamaha with 17 laps remaining of the 30-lap race as he lapped Briton James Ellison. Somehow he kept it upright, but it would not quit and spat him off.
He landed on his back after a flip and slid along ahead of the smashed bike, but thankfully it slowed behind him and the recently-crowned double world champion was able to hobble away. That put Crutchlow all alone in second.
"It was quite exciting at the start as some riders had slicks and others had wet tires," Pedrosa, who made up more than 15 positions on the opening seven laps, said. "When we did the warm-up lap I realised I needed the slicks. I have never started from the pitlane before and I was full of doubts.
"I made a mistake when I was right behind Jorge and then he made one himself. It's fantastic to win the last race."
Valentino Rossi seemed unwilling to risk crashing the Ducati ahead of his return to Yamaha and was lapped by Pedrosa with 12 laps remaining before Ellison passed him.
Crutchlow was all set to become the first British rider since Ron Haslam in 1987 to score back-to-back podium finishes in the top class, but lost the front end of his Yamaha Tech 3 as he leaned over and slipped off. He was alongside the speeding bike for a worrying moment before it veered away into the barriers and he also was able to hobble away.
Japanese Nakasuga, who bettered his sixth in last year's damp Valencia race on just his sixth grand prix appearance, was never in danger from Stoner, who was a little happier with his final bow once the race was over.
"We went way too late to the slick tyres but we brought it home and got on the podium and there are a lot worse ways to end my career," he said.
"I want to thank my team, all my supporters for all these years, all my sponsors. I'm a little disappointed not to be able to win this race."
He added that he had ridden cautiously for the most part because he was worried about hurting the foot he damaged in Indianapolis in August.
The Honda mechanics hung out a sign reading 'Going fishing' for Stoner - advice on how he may spend his time in retirement - as he crossed the line.
Gresini's Michele Pirro was fifth, the best ever result for a CRT rider, followed by Tech 3's Andrea Dovizioso, Karel Abraham, Danilo Petrucci, Ellison and Rossi.
Nicky Hayden, on the sister Ducati, was one of the first to fall of the eight riders who crashed out.
Pedrosa ends the season 18 points behind Lorenzo having won one more race than him - seven against six. Stoner, who missed three races due to ankle surgery, had five wins.
- Sports & Recreation
- Motor Racing
- Repsol Honda