The Honda rider had never performed well at the circuit in the past and said he hated racing there.
His qualifying effort was only good enough for fifth place on the grid but a few changes to his set-up transformed the bike on race day and put his title defence back on course, getting the better of two local favourites in the process.
Yamaha’s 2010 world champion Jorge Lorenzo was second on Sunday while Stoner’s Honda teammate Dani Pedrosa was third in his 100th premium class race.
Lorenzo started from pole and was trying to become the first rider since Valentino Rossi in 2001 to win the first two races of a season and he retained the series lead thanks to winning the opener in Qatar where Stoner finished third.
Double world champion Stoner, though, was ecstatic at his victory on a track where his previous best result was a third placing.
“That is the greatest race I’ve ever done,” said the 26-year-old, who extended his run to 17 successive podium finishes.
“I had a poor start and the conditions were dodgy at first but the bike was working fantastic.
“However, having taken the lead, I felt my arm start to pump and I thought, oh no.
“Thankfully, when I saw the two laps to go marker, more blood seemed to flow through my arm and I felt a lot better and strong enough to hold on.”
The arm weakness cost him probable victory at Qatar as he couldn’t operate his bike at full pace in the closing laps, losing the lead.
Lorenzo said he had desperately wanted to deliver victory to his home fans.
“Sadly, I was not strong enough today and Casey rode a remarkable race,” he said.
Lorenzo heads into the Portuguese round this weekend on 45 points, four clear of Stoner, with Pedrosa third on 36 points.
England’s Cal Crutchlow had a consecutive fourth placing on his Yamaha on Sunday to sit fourth in the standings on 26 points.