LOS ANGELES — After the worst mix-up in Oscar history, “Moonlight” won the Academy Award for best picture at the 89th Academy Awards in Los Angeles — minutes after presenter Warren Beatty mistakenly announced the award for heavily favored “La La Land.”

“Even in my dreams this cannot be true, so the hell with dreams” said “Moonlight” director Barry Jenkins, clearly stunned, but clearly pleased.

“La La Land” won best director for Damien Chazelle, who at 32 became the youngest person to win in that category.

Emma Stone won best actress for her role in “La La Land” as a struggling, aspiring actress who nearly gives up on her Hollywood dream, mustering the courage to make one more try after encouragement from her boyfriend (Ryan Gosling, who also was nominated).

In accepting the award, she thanked Gosling for being the best partner she could imagine on “this crazy adventure.”

Casey Affleck won best actor for his work in “Manchester by the Sea” as a man with a tragic past who, when his brothers dies, must return to his hometown to look after his nephew. Affleck — like his character, a man of few words — said, “It’s an honor to be included” among the nominees.

Viola Davis won best supporting actress for “Fences,” directed by Denzel Washington and based on the August Wilson play. Davis had played the role on Broadway. It was her third nomination and her first win.

In a deeply emotional speech, she said she became an actress to tell “the stories of the people who dream big and never saw those dreams come to fruition, people who fell in love and lost. I became an artist, and thank God I did, because we are the only profession that celebrates what it is to live a life.”

Mahershala Ali won best supporting actor for his role in “Moonlight,” playing a Cuban-born drug dealer who becomes a surrogate father to a troubled young boy in an impoverished Miami neighborhood.

He thanked acting coaches who taught him that “you are in service to these stories and these characters. I’m so blessed I’ve had this opportunity.” He thanked director Jenkins and the rest of the “Moonlight” cast — “any one of them could be up here getting this trophy” — and also his wife, who gave birth to their daughter just four days ago. “I want to thank her for being such a soldier through this process.”

Benj Pasek took home the Academy Award for Best Song for “City of Stars” from “La La Land.” He, along with co-writer Josh Hurwitz (who won for best score) and Justin Paul, actually were nominated twice in the category, the other nod going to “Audition.”

Pasek is having a pretty good year. His Broadway musical “Dear Evan Hansen,” co-written with regular creative partner Paul, is about a troubled kid Pasek knew from school. It’s currently enjoying a successful, and critically acclaimed run on Broadway. It is Pasek’s first Academy Award.

“I want to thank my mom, who is my date tonight. She let me quit a JCC soccer league to be in a musical. This is dedicated to all the kids who sing in the rain and all the moms who let them,” Pasek said while accepting the award.

John Legend bolstered Pasek’s words during the performance by performing both songs. Legend not only co-starred in “La La Land,” he also produced it with Mike Jackson and Ty Stiklorius.

Perhaps the warmest round of applause went to Katherine Johnson, the NASA legend, math whiz and real-life model for the Taraji P. Henson character in “Hidden Figures,” who appeared with Henson and other stars of the movie to help introduce the award for best documentary feature. The award went to “O.J. Made in America.”

“The White Helmets,” a film about rescue workers who’ve saved 82,000 lives in war-torn Syria, won the Academy Award for best documentary short subject.

“The Salesman,” from Iran, won the award for best foreign language film. The director of the film, Asghar Farhadi, a previous Oscar winner (“A Separation”), did not attend in an act of protest. In a statement read at the ceremony, he said, “My absence is out of respect for the people of my country” and the other six nations now subject to travel restrictions due to an executive order issued by the Trump administration.

“Zootopia” won best animated feature, from Disney Animation. The best animated short film award went to “Piper,” from Pixar. “Sing” won the Oscar for best live-action short.

Those who paid good money to see “Suicide Squad” can take solace in the fact it’s now the Oscar-winning “Suicide Squad.” The movie won the Academy Award for best hairstyling and make-up. “Fantastic Beasts and Where to Find Them” won best costume design. “Arrival” won best sound editing, and “Hacksaw Ridge” won best sound mixing and also film editing.

The award for best production design went to “La La Land.” Shot on film in our digital age, “La La Land” also won best cinematography. “The Jungle Book” won the Oscar for best visual effects.

Host Jimmy Kimmel poked fun at stars throughout the evening, teasing Matt Damon for giving the lead role in “Manchester by the Sea” to Casey Affleck so he could make “a Chinese ponytail movie instead.” The host then mentioned “The Great Wall” “went on to lose $80 million.”

The evening began with Justin Timberlake mingling with the audience and taking the stage as he sang his Oscar-nominated song “Can’t Stop the Feeling” from the movie “Trolls.”

There were four honorary Oscars awarded in a ceremony held in November. The winners were Hong Kong superstar Jackie Chan, casting director Lynn Stalmaster, film editor Anne Coates, and legendary documentarian Frederick Wiseman, whose 1969 film “High School” was set at Northeast High School in Philadelphia.