Watched by a crowd of 110,000 at the Circuit Ricardo Tormo, the race pitted the 24-year-old Repsol Honda rider against Ducati's Andrea Dovizioso.
Marquez finished in third place, while Dovizioso retired after crashing into the gravel late into the race, ensuring Marquez, the defending world champion, retained his crown.
It was a tense finale at the end of a close-fought 2017 MotoGP season.
Marquez was defending a 21-point championship lead over Dovizioso heading in the 18th and final race and sped into an early lead from pole position.
The Catalan rider sensibly let combative Frenchman Johann Zarco through to head the race. Behind them, Marquez's Honda teammate Dani Pedrosa and the two Ducatis of Jorge Lorenzo and Dovizioso gave chase.
For long periods, it appeared that Lorenzo was inexplicably holding up his teammate. Signals from his crew seemed to be imploring the Malaga man to allow Dovizioso through, but to no avail.
Meanwhile, Marquez followed Zarco at the front, apparently content to let the Frenchman pursue a maiden premier class win. However, as the laps ticked down, Marquez ran out of patience and swept by, only to lose the front end of his Honda in the following corner.
It was the kind of moment that has come to define his career.
As his bike began to slide from beneath him, Marquez jammed an elbow into the tarmac, lifting the Honda back onto its wheels. The bike hit the gravel, but Marquez somehow managed to maintain control and re-join the race, in fifth place.
Shortly after though, Lorenzo and Dovizioso's races ended. Lorenzo spectacularly crashing out, while Dovizioso -- like Marquez -- succumbed to the lure of the gravel. Unlike his rival though, he was unable to keep his bike upright.
Dani Pedrosa denied Zarco his first MotoGP win, with last year's Moto2 champion finishing second. Marquez clawed his way back to third, meaning he could celebrate his championship win from the podium.
Marquez's victory was his fourth in five years in motorcycling's premier class and his sixth world title overall -- he won the 125cc class in 2010 and the Moto2 crown two years later.
Catalan's fans streamed onto the track, handing Marquez a giant red die, and laying down a mock board game. Of course, the now six-time world champion rolled a six.
"I'm living a dream," Marquez told reporters after the race. "'Six Titles' are big words."
"Today the race was incredibly tense and exciting -- a bit 'Marquez Style'," he laughed. "I made a mistake, but I also made my best save of the year."
Pedrosa was aghast at his teammate's save: "It was incredible. The smoke, the noise, the speed -- wow, impressive!"
Dovizioso was philosophical about his season. "I tried everything and I think that we have to be pleased with this weekend. We weren't as quick as Marquez but we fought to the very end," he said.
"I put myself in the right position but, unfortunately, I didn't have many cards to play."
He also rubbished suggestions that Lorenzo had held him up. "In the end staying behind him helped me ride in a smoother way, so it was positive he was in front of me," he explained.
"We were all at the limit, even Marc who managed to save himself once again from a crash, and I want to congratulate him because also this year he managed to make the difference."
Marquez also had kind words for his rival.
"I'm sorry that Andrea didn't finish the race, as he deserved to do so," he said. "He had an incredible season and I would have liked to have him on the podium with me today."