Shock and chaos spread through the Dolby Theatre when producers of "La La Land" were stopped in the middle of their acceptance speeches to be informed that Beatty had incorrectly read "La La Land" as the winner. "I wasn't trying to be funny," Beatty explained, saying he had seen the name Emma Stone from "La La Land" when he opened his envelope.

Host Jimmy Kimmel came forward to inform the cast that "Moonlight" had indeed won, showing the inside of the envelope as proof. "I knew I would screw this up," said Kimmel, a first-time host. "I promise to never come back."

Damien Chazelle's celebrated musical "La La Land," up for a record-tying 14 nominations, took a while to start cleaning up. But as the night went on, its haul began piling up, winning for cinematography, production, score, song "City of Stars" and best actress for Emma Stone. Chazelle, the 32-year-old filmmaker, also became the youngest to win best director.

Barry Jenkins, the writer-director of "Moonlight" and Tarell Alvin McCraney, whose play it was based on, won for adapted screenplay. "All you people out there who feel like there isn't a mirror out there for you, the academy has your back, the ACLU has your back and for the next four years we will not leave you alone, we will not forget you," said Jenkins.

Kenneth Lonergan, the New York playwright whose last film ("Margaret") was beset by lawsuits and conflict, won best original screenplay. "I love the movies. I love being part of the movies," said Lonergan, who then thanked his star. "Thank you Casey Affleck, Casey Affleck, Casey Affleck."

Shortly later, Affleck — in one of the night's most closely watched categories, Affleck won best actor — his first Oscar — for his soulful, grief-filled performance in "Manchester by the Sea." Affleck and Denzel Washington ("Fences") were seen as neck-and-neck in the category. An admittedly "dumbfounded" Affleck looked shocked when his name was read.

The show kicked off with Justin Timberlake dancing down the Dolby Theatre aisles, singing his ebullient song, "Can't Stop the Feeling," from the animated film "Trolls." It was an early cue that the Oscars would steer, at least in part, toward festiveness rather than heavy-handedness. Protests, boycotts and rallies have swirled ahead of Sunday night's Oscars. But host Kimmel, in his opening monologue, quickly acknowledged that he "was not that guy" to heal a divided America.

The wins for Davis, who co-starred in Denzel Washington's August Wilson adaptation "Fences," and Mahershala Ali, the "Moonlight" co-star, were both widely expected. Their awards marked the first time in more than a decade that multiple Oscar acting honors went to black actors.

"I became an artist, and thank god I did, because we are the only profession to celebrate what it means to live a life," said Davis, the best supporting actress winner. "So here's to August Wilson, who exhumed and exalted the ordinary people."

Ali won best supporting actor for "Moonlight." He glowed on the stage as he informed the crowd that he and his wife, Amatus Sami-Karim, welcomed a daughter four days earlier. The actor thanked his wife for "being such a soldier through the process."

Both stuck to more private reflections over politics. But a more blunt protest came from a winner not in attendance. Best foreign film for the second time went to Asghar Farhadi, director of Iran's "A Salesman." Farhadi, who also won for his "A Separation," had said he wouldn't attend because of Trump's travel band to seven predominantly Muslim nations. Anousheh Ansari, an Iranian astronaut, read a statement from Farhadi.

"I'm sorry I'm not with you tonight," it read. "My absence is out of respect for the people of my country and those of other six nations who have been disrespected by the inhumane law that bans entry of immigrants to the U.S."

The broadcast often veered between such strong personal statements and Kimmel's efforts to keep things a little lighter with bits reminiscent of his late-night show. Shortly before he led a dazed, unsuspecting tour group into the theater, presenter Gael Garcia Bernal, the Mexican actor, declared: "As a migrant worker, as a Mexican, and as a human being, I am against any wall." Rich Moore, one of the three directors of Disney's best animated film winner "Zootopia," described the movie as about "tolerance being more powerful than fear of the other."

Gibson's World War II drama "Hacksaw Ridge" was, surprisingly, the evening's first double winner, taking awards for editing and sound mixing. The bearded Gibson, for a decade a pariah in Hollywood, was seated front and center for the show, and was a frequent presence throughout.

Ezra Edelman's "O.J.: Made in America" took best documentary, making it — at 467 minutes — the longest Oscar winner ever, beating out the 1969 Best Foreign Language Film winner "War and Peace" (431 minutes). Edelman's documentary, while it received an Oscar-qualifying theatrical release, was seen by most on ESPN as a serial, prompting some to claim its place was at the Emmys, not the Oscars.

"This is also for other victims, victims of police violence, police brutality," Edelman said. "This is their story as it is Ron and Nicole's."

The "OscarsSoWhite" crisis of the last two years was largely quelled this season by a richly diverse slate of nominees, thanks to films like "Moonlight," ''Fences" and "Hidden Figures." A record six black actors are nominated. For the first time ever, a person of color is nominated in each acting category. And four of the five best documentary nominees were also directed by black filmmakers.

"I want to say thank you to President Trump," Kimmel said in the opening. "Remember last year when it seemed like the Oscars were racist?"

The nominees follow the efforts by Academy of Motions Pictures Arts and Sciences President Cheryl Boone Isaacs to diversify the membership of the largely white, older and male film academy. In June, the academy added 683 new members: 46 percent of them were female; 41-percent were nonwhite; and they pulled from 59 countries.

"Tonight is proof that art has no borders, no single language and does not belong to a single faith," said Isaacs.