The team from La La Land was in the middle of its acceptance speeches when the mistake was discovered.

Stone said backstage afterwards: “Is that the craziest Oscar moment of all time? Cool! It’s going to be history.”

PriceWaterhouseCooper, the accountancy firm responsible for counting the ballots, said in a statement: “We sincerely apologise to Moonlight, La La Land, Warren Beatty, Faye Dunaway, and Oscar viewers for the error that was made during the award announcement for best picture.

“The presenters had mistakenly been given the wrong category envelope and when discovered, was immediately corrected. We are currently investigating how this could have happened, and deeply regret that this occurred.”

Musical La La Land won six Oscars including best director and best actress. Moonlight also won adapted screenplay and best supporting actor.

Damien Chazelle, director of La La Land, became the youngest filmmaker to win a best director Oscar at the age of 32.

Beatty’s Bonnie and Clyde co-star Faye Dunaway announced La La Land had taken the best picture prize – but then the musical’s producer Jordan Horowitz announced there had been a mistake.

He said: “This is not a joke. Moonlight is best picture,” and showed the camera the card that revealed the winner.

Two La La Land producers had already given their acceptance speeches before the mistake was revealed.

Host Jimmy Kimmel joked that he knew he would mess up compering the ceremony, and added: “Personally I blame Steve Harvey for this,” referring to Harvey’s mistake in announcing the Miss Universe winner in 2015.

Beatty returned to the microphone to say: “I want to tell you what happened. I opened the envelope and it said ‘Emma Stone, La La Land’, and that is why I took such a long look at Faye and at you.

“I wasn’t trying to be funny. This is Moonlight for best picture.”

The film’s director Barry Jenkins said: “Very clearly even in my dreams this can’t be true. But to hell with it because this is true. It’s true, its not fake.”

Paying tribute to the team behind La La Land for the way they handled the mistake, he said: “We have been on the road with these guys and it was so gracious and so generous of them.”

Emma Stone, who won the coveted best actress prize, said backstage: “I’m so excited for Moonlight. Of course it was an amazing thing to hear La La Land and I would love to win best picture. But we are so excited for Moonlight. I think it is one of the best films of all time.

“Is that the craziest Oscar moment of all time? Cool! It’s going to be history.”

She also said that she still had the envelope for best actress in her hand, although there are always two envelopes (one for back-up), which might explain why the mistake occurred.

La La Land also picked up best cinematography, best score and best original song for City of Stars.

It also won best production design.

Manchester by the Sea won two awards – one of them was for best original screenplay. (Courtesy BBC)