Miss Colombia Ariadna Gutierrez thought she had won the Miss Universe pageant.

But then the host Steve Harvey said he'd made a terrible mistake.

"Okay, folks," he said. "I have to apologize."

Miss Colombia was the first runner-up, he said, holding up the card that contained the official results.

The real winner was Miss Philippines, Pia Alonzo Wurtzbach, who looked astonished by the sudden turn of events.

The almost unbelievable ending to the pageant was televised live in many countries, including on the Fox network in the United States on Sunday night.

Wurtzbach covered her mouth in shock when Harvey announced the correction. Then she walked out to the front of the stage and waited for Gutierrez to hand over the crown.

Harvey stood to the side, visibly embarrassed, while the crowd cheered. On the card he was holding, both the winner and first runner-up's names were printed in small type.

Harvey took responsibility and called it a "horrible mistake."

Social networking sites lit up with instant reaction. ESPN's Darren Rovell called it "the worst mistake in TV awards show history."

Harvey is a beloved comedian best known for hosting the game show "Family Feud" and daily talk shows on radio and TV.

Observers immediately pointed out that he has much more experience with taped shows than with live TV.

After the pageant snafu, he tweeted, "I'd like to apologize wholeheartedly to Miss Colombia & Miss Philippines for my huge mistake. I feel terrible."

He followed up and said, "Secondly, I'd like to apologize to the viewers at that I disappointed as well. Again it was an honest mistake."

Pageant organizers also issued a statement apologizing to Miss Colombia and Miss Philippines, as well as their fans.

"Unfortunately, a live telecast means that human error can come into play," the organizers said. "We witnessed that tonight when the wrong winner was initially announced."

On social networking sites, some people quickly came to Harvey's defense; Earvin Magic Johnson tweeted, "we've all made mistakes in our careers & lives." He encouraged Harvey to "keep the faith and keep going strong!"

Charles M. Blow, an op-ed columnist at the New York Times, cautioned people not to be too hard on Harvey.

"Ok, [he] made a huge mistake. BUT, how many have we all made?! Seriously, don't laugh too loud. Karma might hear you..." Blow tweeted.

Ok, @IAmSteveHarvey made a huge mistake. BUT, how many have we all made?! Seriously, don't laugh too loud. Karma might hear you... — Charles M. Blow (@CharlesMBlow) December 21, 2015

But others made plenty of jokes at Harvey's expense.

If only Steve Harvey had experience reading correct answers off of cards in front of a live audience. — Ramzy Nasrallah (@ramzy) December 21, 2015

The screw-up happened at an important moment of transition for Miss Universe. The pageant was owned by Donald Trump and NBCUniversal until earlier this year. When the business partners split up in the midst of a Trump campaign controversy, the giant talent agency WME/IMG took control of the pageant.

If nothing else, the mistake provided the pageant with a sudden jolt of attention.

Vulture's Joe Adalian, a veteran television industry reporter, said it "wouldn't shock me" if the crown switcheroo was actually a planned stunt. "Everybody wins here," he said.

Trump, through his Twitter account, had been touting the pageant's new owners earlier in the evening.

After the error, he retweeted a fan who asked, "Where's @realDonaldTrump when you need em?"

And on Monday morning he followed up with this: "Very sad what happened last night at the Miss Universe Pageant. I sold it 6 months ago for a record price. This would never have happened!"