Toni Elias of Spain edged Valentino Rossi in a photo finish on Sunday to win the Portuguese Grand Prix.
American rider Nicky Hayden crashed on the fifth lap and is eight points behind Rossi in the overall standings. The Italian is looking for a sixth straight world title.
Elias, riding a Honda, and Rossi on a Yamaha battled for the lead throughout the final lap until Elias pulled wide into the final stretch. A video replay determined he was a wheel in front of Rossi, winning in 46 minutes, 8.739 seconds.
"It is like a dream what I have done here," Elias said. "There were several nerve-wracking moments on the final laps, but I held my nerve and shadowed Valentino. I still didn't know whether I had got it on the line."
Kenny Roberts Jr of the US finished third for KR211V in 46:08.915.
Dani Pedrosa attempted to overtake Honda teammate Hayden on an inside turn on the fifth lap, but they brushed tires and both crashed. Hayden slammed his fists onto the gravel and was screaming as he left the track.
Rossi, who trailed by 12 points entering the race where he has never missed the podium, has 244 points. Hayden, with 236, has finished in the top three only once in five races at the Estoril track.
"I had the dilemma of pushing for first or staying back -- I was constant through the race, but not as fast as in qualifying. We have two weeks to work on it, and eight points aren't enough of a window, but it does allow us to finish second if Hayden wins in Valencia," Rossi said.
The last race is in Valencia, Spain, on Oct. 30 with 25 points for the winner, 20 for second and 16 for third.
Earlier, Honda's Andrea Dovizioso of Italy won the 26-lap 250cc race in 44:30.727 to cut championship leader Jorge Lorenzo's overall lead from 27 to 13. The Spaniard finished fifth. KTM rider Hiroshi Aoyama couldn't make it two wins in a row, finishing in 44:30.742 for second, while Alex De Angelis of Italy was third.
In the 125cc race, world champion Alvaro Bautista of Spain won his eighth race of the season in 40:48.972, more than 15 seconds ahead of Aprilia teammate and countryman Hector Faubel.
Faubel's time of 41:03.890 was 0.14 better than third-place Mika Kallio of Finland.
The 21-year-old Bautista moved to 325 points, 83 more than KTM's Kallio. Bautista clinched the championship at the Australia GP last month.