"Even in my dreams, this could not be true," "Moonlight" director Barry Jenkins said. "But to hell with dreams, I'm done with it."
After Beatty explained that he was given the wrong envelope, and emcee Jimmy Kimmel intervened with some ad-libbed jokes, the "Moonlight" team took the stage.
"I'm still not sure this is real," said Adele Romanski, one of "Moonlight's" producers. She said she hoped the film, and the Best Picture win, would be "inspiring to little black boys and brown girls, and people who feel marginalized."
"Moonlight" also won Oscars for adapted screenplay, written by Jenkins and Tarell Alvin McCraney, and for Mahershala Ali's supporting performance as Juan, a drug dealer who becomes a father figure to the movie's main character, a boy named Chiron.
In his acceptance speech, Ali, the first Muslim to win an acting Oscar, quoted the lessons of his acting teachers: "It's not about you. It's about these characters. You're in service to these stories and their characters."
"La La Land" took the most statuettes, with six. Emma Stone won Best Actress for playing Mia, a struggling actress who falls for a jazz musician (Ryan Gosling). Damien Chazelle, at 32, became the youngest man to win a Best Director Oscar. Justin Hurwitz won for original score, and for co-writing the song "City of Stars." The movie also won for Linus Sandgren's cinematography and David Wasco's production design.
Casey Affleck took the award for Best Actor, for his role as a grief-paralyzed father in "Manchester by the Sea." That film also won an original screenplay Oscar for Kenneth Lonergan.
Viola Davis won the supporting-actress Oscar for her role as Rose Maxson, the downtrodden wife of a garbageman, in August Wilson's "Fences," the same role for which she won a Tony in 2010.
"I became an artist, and thank God I did," Davis said in a tearful acceptance speech. "We have the only profession that celebrates what it means to live a life."
The night was marked with some commentary about President Donald Trump, though his name was most often invoked by Kimmel as a punchline.
The strongest acceptance speech was from a filmmaker not in the theater: Iranian director Asghar Farhadi, whose drama "The Salesman" won the foreign-language category. Iranian astronaut Anousheh Ansar read a statement from Farhadi, who skipped the ceremony to protest Trump's travel ban on people from majority-Muslim countries.
"Dividing the world into the 'us' and 'our enemies' categories creates fear," Farhadi's statement read in part. He added that films "create empathy between us and others, a quality we need today more than ever."
Several attendees wore blue ribbons, in support of the American Civil Liberties Union. And a few presenters went off-script to make a political comment. Mexican actor Gael Garcia Bernal, for one, dinged Trump's immigration policy: "I'm against any form of wall that wants to separate us."