Oscar winner, take two. Barry Jenkins' "Moonlight" not, as it turned out, "La La Land" won best picture at the Academy Awards in a historic Oscar upset and an unprecedented fiasco that saw one winner swapped for another while the "La La Land" producers were in mid-speech.

LOS ANGELES Oscar winner, take two.

Barry Jenkins' "Moonlight" not, as it turned out, "La La Land" won best picture at the Academy Awards in a historic Oscar upset and an unprecedented fiasco that saw one winner swapped for another while the "La La Land" producers were in mid-speech.

Presenters Warren Beatty and Faye Dunaway apparently took the wrong envelope the one for best actress winner Emma Stone onto the stage. When they realized the mistake, representatives for ballot tabulators Price Waterhouse Coopers raced onstage to stop the acceptance speech.

But backstage, Stone said she was holding with her envelope at the time. "I think everyone's in a state of confusion still," said Stone. Later the actress, who pledged her deep love of "Moonlight," added, "Is that the craziest Oscar moment of all time? Cool!"

It was, nevertheless, a shocking upset considering that "La La Land" came in with 14 nominations, a record that tied it with "Titanic" and "All About Eve." Barry Jenkins' tender, bathed-in-blue coming-of-age drama, made for just $1.5 million, is an unusually small Oscar winner. Having made just over $22 million as of Sunday at the box office, it's one of the lowest grossing best-picture winners ever.

"Even in my dreams this cannot be true," said an astonished Jenkins, once he reached the stage.

Host Jimmy Kimmel had come 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."

Producer Jordan Horwitz then graciously passed his statue to the "Moonlight" producers.

Up until the chaotic end, the telecast had seesawed between jabs at Donald Trump and passionate arguments for inclusivity, with awards going to "La La Land," ''Moonlight" and "Manchester by the Sea."

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.

"This was a movie about love and I was luckily enough to fall in love while making it," said Chazelle, speaking about his girlfriend and Oscars date, Olivia Hamilton.

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.

"Man I wish I had something bigger and more meaningful to say," said Affleck, who hugged his more famous brother, Ben, before taking the stage.

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.

But he still, pointedly, led a standing ovation for the "overrated" Meryl Streep. He later tweaked the president by tweeting to him on air, including telling him that Streep "says hi."

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.

Edelman dedicated the award to the victims of the famous crime, Nicole Brown Simpson and Ronald Goldman.

"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.