Rossi, seeking what would have been his 81st win in the elite MotoGP class, said he could take a lot out of the race, having been written off last season as a spent force.
"At the beginning I was a little not clear in my mind, do I attack? Then I said 'I go, I try', but after Marc was stronger.
"I had the potential to try at the end but unfortunately he was a little too far. But anyway it's a great result and I hope to continue like this."
In a thrilling race beneath the Losail circuit floodlights, 2010 and 2012 world champion Jorge Lorenzo was done and dusted inside the first lap.
The Spaniard, the runner-up to Marquez in the 2013 world championship, had started in fifth place but snatched the lead on the first bend.
However, he suffered a dramatic race-ending crash at the end of the opening lap on his factory Yamaha which must have been painful for a man who twice broke his collarbone last year.
"It was a high speed crash but not on the dangerous side," said Lorenzo.
"I made the mistake of a junior. The tyres are different from last year and the temperatures are colder than they were in qualifying. I didn't take these things into account."
Germany's Stefan Bradl, on a Honda, soon found himself in the front but his evening also ended prematurely when he came off the track on the ninth lap.
Rossi, who had started in 10th place on the grid, then took the lead from Marquez and held it for five laps as the 35-year-old Italian sensed a first win since Assen last year.
However, Marquez, on the faster Honda, slipped by him on the 13th lap.
They swapped the lead twice in a nail-biting penultimate lap, but Marquez had too much power for the Italian great.
-AAP