The Italian took the lead on the sixth of 22 laps when Stoner, who had started on pole position and was chasing his fourth successive Qatar win, fell while holding a two second advantage.
From there Rossi controlled the pace, pulling clear of the pack only in the final few laps to win the night race at the Losail circuit by 1.022 seconds.
"A great way to start the season for us, for me, for my team, for Yamaha," said the Italian. "Another first and second and these 25 points in this track are like gold for us, for our championship.
"I think it was from 2005 (that) I didn't win the first race (of the season), so we try to continue like this."
Rossi's Yamaha team mate Jorge Lorenzo worked his way through the pack to finish second.
The Spaniard, riding with stitches in his right hand after an accident in testing, took third place from Ducati rider Nicky Hayden on the 20th lap and then went up the inside of Honda's Andrea Dovizioso on the final lap to give his team the one-two.
"I struggled a lot at this track with the sliding and I was riding at the limit physically and also on my riding style," he said.
"At the end I did the maximum I can to overtake Hayden and Andrea. I am also very tired. This second position is fantastic and also the victory of Vale for Yamaha is perfect."
TOMIZAWA VICTORY
Hayden passed Dovizioso two turns from the end, but the Italian powered past down the front straight to take the final podium spot by .011 secs.
"It was a strange thing, because to overtake a rider inside at the last corner is not normal," said Dovizioso. "But (Hayden) made a small mistake so I can exit in the same level and my bike in the straight is so strong, so fast so I can get to the podium."
Japanese rider Shoya Tomizawa became the first rider to win a Moto2 race, the class which replaced the 250cc World Championship.
The 19-year-old gave no indication of his potential in 2009, with 10th his best finish, but he put on a masterclass on the Honda-powered Suter chassis.
Starting ninth on the 41-rider grid, Tomizawa took the lead on the sixth of 20 laps and never gave it up as he went on to win by 4.656 seconds.
Spaniard Alex Debon stole second place from Frenchman Jules Cluzel six turns from the end of the race.
Nicol Terol began the night's action by leading a Spanish sweep of the first four places in the 125cc race for a tactically brilliant third career win.
The Aprilia rider was among the seven strong leading pack when he hit the front on the 15th of 18 laps with the fastest race lap and went on to win by 2.395. Efren Vazquez and Marc Marquez filled out the podium, with Pol Espargaro a close fourth.
The next race is the Japanese Grand Prix at Motegi in two weeks' time.