LOS ANGELES — In an epic flub that drew gasps of horror — and joy — at the Dolby Theater here, Faye Dunaway mistakenly named “La La Land” best picture at the 89th Academy Awards on Sunday night, but in reality “Moonlight” won the top prize.

The producers of “La La Land” were still thanking their families and fellow artists when the interjection came that “Moonlight” had in fact won, as everyone wondered if that was a joke. But it wasn’t, and the “La La Land” people quickly exited the stage as producers and stars of “Moonlight,” just as stunned as everyone else, walked on.

Warren Beatty and Ms. Dunaway had presented the best picture award. When Mr. Beatty opened the envelope, he took an extended pause before showing the card to Ms. Dunaway, who then announced “La La Land” as the winner.

“I want to tell you what happened,” Mr. Beatty said in the chaotic moments after “Moonlight” was announced as the winner. “I opened the envelope, and it said ‘Emma Stone, La La Land.’ That’s why I took such a long look at Faye and at you. I wasn’t trying to be funny. This is ‘Moonlight,’ the best picture.”

“Moonlight,” the story of a young, gay, black man, won three statuettes in total, including best adapted screenplay and best supporting actor.