(CNN) -- It was lost in the confusion of the Oscar envelope snafu, but "Moonlight" made history.

The coming-of-age drama about a gay black man growing up in Miami became the first film with an all-black cast to win the Academy Award for best picture.

The movie, whose cast includes best supporting actor winner Mahershala Ali, Naomie Harris, Trevante Rhodes and Janelle Monáe, has been a critical darling during awards season.

With the win, it shattered a glass ceiling for black films.

"Very clearly, even in my dreams this could not be true," director Barry Jenkins said in amazement when it was announced that "Moonlight," not "La La Land," had won. "But to hell with dreams, I'm done with it, 'cause this is true. Oh my goodness."

In 2014, "12 Years a Slave" won best picture, but its cast was not all black.

Both "Moonlight" and "12 Years" were produced by Brad Pitt's Plan B company.

"Moonlight" made Oscar history in other ways.

Ali, who played a sympathetic drug dealer who mentors a bullied young man, is the first Muslim actor to win best supporting actor.

Jenkins became the first African American to score nominations for best director, best picture and best adapted screenplay in the same year. The film's co-editor, Joi McMillon, became the first African American to earn a nomination for achievement in film editing.

The "Moonlight" win came in a year in which the Academy has been hailed for more diversity.

White actors had especially dominated the major acting categories for two years, giving rise to the #OscarsSoWhite hashtag. This year, seven of the 20 nominees were people of color.

Viola Davis, who won best supporting actress, became only the second black woman to win an Emmy, an Oscar and a Tony for acting. Whoopi Goldberg is the other, and the only black actor to have a so-called EGOT -- an Emmy, Grammy, Tony and Oscar.

April Reign, who created the #OscarsSoWhite hashtag, tweeted Sunday night about the importance of the evening.

"Viola, Mahershala, and the wins for Moonlight happened because they were DESERVED," she wrote. "Not because of #OscarsSoWhite. I want that very clear."

Earlier in the evening, Jenkins and Tarell Alvin McCraney, who wrote the play that became "Moonlight" and co-wrote the screenplay, won the Oscar for best adapted screenplay. The pair paid homage to the disenfranchised in their acceptance speech for that award.

Jenkins said: "All you people out there who feel like there's no mirror for you, that your life is not reflected, the Academy has your back, the ACLU has your back, we have your back and for the next four years we will not leave you alone, we will not forget you."