The Repsol Honda rider stalked former champion Lorenzo for two thirds of the 32-lap race at the Californian circuit before passing the Spaniard over the finish line.
Australian Stoner, who has announced he will retire at the end of the season, put his victory down to his race strategy.
Stoner told the BBC: "I wanted to get to the front immediately and see if I could pull a gap.
"I didn't want to risk it and pass him somewhere I was not comfortable."
Lorenzo admitted he had been second best to his rival.
"I made a mistake and I almost crashed," Lorenzo said. "I could not keep the pace that I did in the beginning."
With Stoner taking the win, he closed the gap in the points standings to 32 between himself in third and Lorenzo.
Watch: Casey Stoner wins US.. More Videos
Third in the race was Stoner's team-mate Dani Pedrosa, which left him second in the standings - 23 points behind his countryman.
Lorenzo's team-mate Ben Spies had looked set for fourth place on a weekend he announced he would be leaving Yamaha next term.
But Spies was thrown from his Yamaha in the downhill Corkscrew corner and was lucky to escape serious injury in his home race.
That left Italian Andrea Dovizioso to claim fourth ahead of his British team-mate Cal Crutchlow as the Monster Tech 3 Yamahas battled all race long.
American Nicky Hayden celebrated signing a new contract with Ducati by taking sixth place ahead of Stefan Bradl (LCR Honda), Alvaro Bautista (San Carlo Honda), Aleix Espargaro (Aspar) and Karel Abraham (Cardion Ducati).
Multiple world champion Valentino Rossi had a high-speed crash at the entry to the Corkscrew but walked away without serious injury.