(Nicki DeMarco/The Washington Post)

In a shocking upset combined with a bizarre blunder, “Moonlight,” a spare, quiet character study of a young black man at war with his own sexuality, won best picture at Sunday’s Academy Awards ceremony.

Presenters Warren Beatty and Faye Dunaway had originally announced anticipated favorite “La La Land” as the winner of the night’s biggest award. But midway into that production team’s acceptance speeches, an Oscars staffer with a headset appeared on stage and whispered news to “La La Land” producer Jordan Horowitz. Horowitz then rushed to the microphone. “There’s been a mistake,” he said. “ ‘Moonlight,’ you guys won.”

Beatty came to the microphone again and offered an explanation: his cue card, he said, had the name of “La La Land” best actress winner Emma Stone on it, so the duo decided to announce that picture as the winner.

In a surreal scene, the stage filled with cast and crew of both films, as confused viewers at home and in the Dolby Theater tried to figure out if they were privy to an unprecedented foul-up or an elaborate joke.

It was the first time in the 89-year history of the awards that an incorrect winner had been announced. “Moonlight” writer/director Barry Jenkins seemed stunned as he accepted the gently-used trophy. “Even in my dreams, this could not be true,” Jenkins said. “But to hell with dreams!”

Barry Jenkins and Adele Romanski accept the Oscar for best picture for “Moonlight.” (Aaron Poole/AMPAS/EPA)

It was his second time at the podium, having already accepted the award for best adapted screenplay. In his first speech, he reached out to “all you people who feel like your life is not reflected,” and held his trophy aloft. “The Academy has your back.”

“La La Land,” a whimsical, brightly colored throwback to classic movie musicals, had been nominated for a record-tying 14 awards. Though it did not win the ultimate prize, it made a strong showing by taking home six of them, including best director, actress, score and original song.

“This was a movie about love,” said director Damien Chazelle who, at 32, became the youngest best director in Academy Award history.

“A moment like this is a huge confluence of luck and opportunity,” said Emma Stone, who had been a critical favorite for her singing, dancing role as a persevering actress trying to both launch a career and hang onto a relationship. She promised to find the film’s crew after the ceremony, to thank them personally and individually: “I’m going to hug the hell out of you, when feelings reenter my body.” (Later, backstage, she acknowledged the insanity of the best picture mix-up. “Is this the craziest moment in Oscar history? Cool, we made history!”)

Casey Affleck, another anticipated favorite, won best actor for portraying a Massachusetts janitor buried in grief in the quiet drama “Manchester by the Sea.”

“Man, I wish I had something bigger and more meaningful to say,” Affleck said, at a loss for words from behind the podium. “But I’m just dumbfounded.” He thanked the film’s writer and director, Kenneth Lonergan, who earlier in the evening had accepted an award for best original screenplay.

Prior to the best picture bungle, the emotional highlight of the awards had come midway through the ceremony, with Viola Davis’s poignant, philosophical acceptance speech for her best supporting actress win.

“I became an artist — and thank God I did — because we are the only profession that celebrates what it means to live a life,” said Davis, who embodied a self-sacrificing wife in working-class 1950s Pittsburgh in the best-picture-nominated “Fences.”

“You know there is one place that all the people with the greatest potential are gathered, and that’s the graveyard,” said Davis, a three-time nominee who, with her win, became one of 23 performers to be awarded an Oscar, an Emmy and a Tony. “People ask me all the time, what kinds of stories do you want to tell?. . . And I say: the stories of the people who dream big and never saw those dreams come to fruition. To people who loved and lost.”

Viola Davis accepts best supporting actress for “Fences.” (Kevin Winter/Getty Images)

Mahershala Ali accepts the award for best supporting actor in “Moonlight.” (Chris Pizzello/Invision/AP)

After last year’s #OscarsSoWhite, a grass-roots campaign about lack of diversity in awards ceremonies, led to rule changes in academy membership, Sunday’s ceremony included the most diverse nominee list in history. Performers of color were represented in all of the acting categories. Three of the nine best-picture nominees told stories of African American experiences in the United States, as did three of the five films nominated for best documentary. The winner for best animated feature, “Zootopia,” was an allegory of racial profiling told via foxes and rabbits.

An hour before Davis’s emotional acceptance speech, Mahershala Ali became the first Muslim actor to win an Oscar and the first African American man in more than a decade to win one. He was honored as best supporting actor for his role in “Moonlight.”

“My grandma would want me to button up,” he said, arriving at the podium to discover that his jacket was undone. Ali, whose role as a conflicted Miami drug dealer mentoring a young gay boy had been a critical favorite, thanked his acting teachers for teaching him to put his own ego aside, “in service to these stories and these characters.”

He ended by thanking his wife, who had given birth to their daughter just four days before the ceremony.

The best documentary feature award went to “O.J.: Made in America,” ESPN’s revelatory 467-minute multi-part series about O.J. Simpson’s rise and fall. In his acceptance speech, director Ezra Edelman — a graduate of Washington’s Sidwell Friends School, the son of Hillary Clinton’s mentor Marian Wright Edelman — dedicated the award to murder victims Nicole Brown Simpson and Ron Goldman. “This is for them and their families,” he said. “This is also for others — the victims of police violence, police brutality, racially motivated violence and criminal injustice.”

This year’s movie-awards season had been populated by political statements in winners’ speeches. Most notably, Meryl Streep’s Golden Globes diatribe against President Trump was widely circulated, and raised the ire of the president himself.

Host Jimmy Kimmel. (Chris Pizzello/Invision/AP)

Politics was present at the Academy Awards, but early in the broadcast it was muted, and conveyed mostly via the ACLU-supporting blue ribbons worn by many attendees on their dresses and lapels, as well as in scattered zingers delivered by host Jimmy Kimmel.

“The show is being watched live by millions of Americans and more than 225 countries who now hate us,” Kimmel deadpanned at the beginning of the show. Later, he jokingly booted any media “with the word ‘Times’ in it” from the theater, saying that he had no patience “for fake news.”

Later in the broadcast, “The Salesman” won for best foreign film, but Iranian director Asghar Farhadi boycotted the ceremony. He sent a statement to be read in his stead, explaining that his absence was in solidarity for the refugees from the countries included in Trump’s attempt at an entry ban by executive order. “Dividing the world into the ‘us’ and ‘my enemies’ categories creates fear,” the statement read.

Despite its ultimate success in the evening, “La La Land,” was mostly absent in the early part of the ceremony, leaving room for unlikely competitors: The award for best costume design went to box office disappointment “Fantastic Beasts and Where to Find Them.” The award for best makeup went to the critically reviled “Suicide Squad.”

The award for the little-understood category of best sound mixing ended up being a surprise audience favorite when it went to “Hacksaw Ridge’s” Kevin O’Connell, a veteran workhorse who had been nominated 21 times but had never won.

“I can’t even tell you what this means to me,” he said, mentioning his mother, who helped him get his first industry job four decades ago. When he asked her at the time how he could thank her, he said, his mother told him to work hard and one day thank her from the podium after he won an Oscar. “Mom, I know you’re looking down on me tonight,” O’Connell said. “So, thank you.”