Hayden, who claimed his maiden career win on the undulating Laguna Seca circuit last year, stalked pole sitter Chris Vermeulen through the early stages of the race until passing the Australian on lap 17 then charging home 3.18 seconds ahead of Honda team mate Dani Pedrosa of Spain.
Italy's Marco Melandri, racing with a broken collar bone, was third, also on a Honda.
Five-time 500cc champion Rossi started well back from 10th position after another disappointing qualifying effort, but was quickly on the charge working his way up to sixth midway through the 32-lap race.
But with three laps remaining disaster struck as blue smoke began pouring out of the back of the Italian's Yamaha leaving him on the sidelines and out of the points.
Hayden's second victory of the season gives the American 194 points and a 34-point lead over Pedrosa with six races remaining.
Rossi, who had arrived in California trailing Hayden by 26 points, slips to fourth in the standings with 143 points.
"I didn't know I had it today," Hayden told reporters. "I was so nervous before the race leading the points.
"I swear, it feels better (to win) than last year if that's possible.
"This is a great day, really nice for the championship and to win in front of these great fans.
"I didn't let them down today."
After from coming from 11th to take victory last week at the German Grand Prix, Rossi had looked poised to stage another riveting fightback and put more pressure on Hayden until his engine expired, marking the third time he has failed to finish this season.
"I started seeing flags and smelled oil and I really got nervous," said Rossi. "I can't worry about that (Hayden), I just rode my heart out."
The MotoGP schedule now shifts back to Europe for the Czech Grand Prix on August 19.
(Writing by Steve Keating in Toronto)