Pacquiao had been down in the third round but knocked Marquez down in the fifth and the two were exchanging heavy blows in the sixth round before Marquez threw a right hand that flattened Pacquiao face down on the canvas at 2:59 of the sixth round.
The referee waved the fight to an end as Marquez celebrated and the sold-out crowd at the MGM erupted. Pacquiao was down for about two minutes before his handlers managed to get him up.
After being helped to his corner, Pacquiao sat on a stool, blew his nose and stared vacantly ahead as his handlers cut his gloves off. It was a stunning end to a furious fight and it may have signalled the end of Pacquiao's career.
"I threw a perfect punch," Marquez said. "I knew Manny could knock me out at any time."
Marquez had vowed to finally beat Pacquiao after losing two close fights and settling for a draw in the first fight. But after Pacquiao knocked him down in the fifth round and was landing big left hands, it looked like it would be Pacquiao's night.
The two came out for the sixth round and the pace was just as relentless. Both were landing big punches and both were brawling when suddenly as the round came to close Marquez shot out a right hand that landed flush to the jaw of Pacquiao, who crumpled to the canvas in a heap.
"I felt he was coming to knock me out the last three rounds and I knew he was going to be wide open," Marquez said.
It was the second loss in a row for Pacquiao, who dropped a decision to Timothy Bradley in June and who had vowed to regain his prominence in the ring.
Pacquiao was aggressive from the opening bell, but paid the price in the third round when he got by a Marquez right hand that put him down. Pacquiao got back up and seemingly took control of the fight, dropping Marquez in the fifth round and landing the bigger punches until he was dropped
"I got hit by a punch I didn't see," Pacquiao said.
Pacquiao, who earned more than $20 million for the fight, was ahead 47-46 on all three scorecards after the fifth round.
There was no title at stake in the 147-pound fight, but that didn't stop 16,348 fans from filling the MGM Grand Arena and roaring in unison from the opening bell as the two fighters went after each other.
Ringside punching stats underscored the ferocity of the bout, showing Pacquiao landing 94-of-256 punches to 52 of 246 for Marquez. But it was the one big right hand from Marquez that counted more than anything, knocking Pacquiao out for the first time in a career that goes back 17 years.
"He was in charge," Pacquiao's trainer Freddie Roach said. "He just got a little too careless and got hit with a punch he didn't see."
Promoter Bob Arum immediately said he could see a fifth fight between the two boxers, and a dazed Pacquiao seemed to agree.
"Why not?" he said.
Pacquiao weighed the class limit of 147 pounds, but it was Marquez who looked like the stronger fight entering the ring after having bulked up with the help of a strength conditioner even though he weighed in at 143 pounds. In their earlier fights, Pacquiao had been the bigger puncher, knocking Marquez down a total of four times, but on this night it was Marquez who had the biggest punch.
The stunning knockout was the first real loss by Pacquiao in seven years. He lost a close decision to Bradley in his last fight, but most ringside observers believed he had won it fairly convincingly.
Marquez improved to 55-6-1 with 40 knockouts, while Pacquiao fell to 54-5-2.