After a shock ending that would've won a scriptwriter an Academy Award, there's no denying what was the major moment of the 2017 Oscars. 

After Hollywood legend Faye Dunaway had called La La Land as the Best Picture winner, it was revealed that the wrong film had been announced and Moonlight was the real winner.

It was a stunning end to what had been a seamless show up until that point, with Jimmy Kimmel proving to be an excellent host. The true successor to Billy Crystal has been determined.

Naturally, after the most dramatic moment in its 89-year history, social media exploded. 

But how did such a massive gaffe occur in the first place?

PricewaterhouseCoopers, the accountancy firm that has overseen the counting of the Oscars ballots for 83 years, issued an apology saying the presenters "had mistakenly been given the wrong category envelope and when discovered, was immediately corrected."

They said an investigation is now underway to determine how it happened and how the normal fail safes came a cropper.

We need your consent to load this Facebook contentWe use Facebook to manage extra content that can set cookies on your device and collect data about your activity. Please review their details and accept them to load the content.Manage Preferences

Their initial response seems to check out, as Warren Beatty was photographed on stage holding the wrong envelope for Actress in a Leading Role which had just been given to La La Land's Emma Stone.

Warren Beatty holding the Actress in a Leading Role envelope instead of Best Picture

It will call into question the company's extremely rigorous counting system which is checked and double checked to make sure mistakes like this aren't made.

There are duplicate envelopes containing all of the winners which are held by the firm's partners, Brian Cullinan and Martha Ruiz, who are seen standing to the left and right of the stage. 

Depending on which side of the stage the presenters are entering, Cullinan or Ruiz hand them the envelope for the award they are announcing, as Cullinan explained when he spoke to The Business on RTÉ Radio 1 at the weekend.

PWC partners Brian Cullinan and Martha Ruiz bring the winners envelopes to the ceremony

In this case, they handed the wrong envelope to Warren Beatty, who looked confused and paused after looking at the card, even checking if there was anything else inside the envelope. After a long pause, he showed the piece of card to his co-presenter Dunaway, who saw the name of the film and said "La La Land".

In a scenario such as this, either Cullinan or Ruiz have to appear on stage to correct the error. However, there seems to have been a delay in them intervening, as the La La Land producers had already given two speeches accepting the award.

Warren Beatty looked puzzled after he opened the envelope

The mistake was then addressed by La La Land producer Jordan Horowitz, who took to the microphone to reveal that Moonlight had been named best picture while holding up the correct winners card.

After the error was cleared up, 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."

Emma Stone also initially cast some doubt over the mix-up. The actress, who most likely is unaware that there are two duplicate sets of winners cards, said she was holding onto her winners card as the best picture was announced.

She said: "I also was holding my best actress in a leading role card that entire time. I don't mean to start stuff but whatever story that was, I had that card. So I'm not sure what happened."

Emma Stone initially cast doubt over mix-up

Cullinan and Ruiz, who are the only people to know the results of the awards before they are announced, are tasked with transporting the winners cards in brief cases to the awards ceremony in separate cars with a security detail, in case something goes wrong on the way to the Dolby Theatre.

The results are subject to the utmost secrecy ahead of the ceremony, and are locked in a safe until the big day. 

The supposedly foolproof system is sure to come under review after this major error sent shock waves across the Dolby Theatre and beyond and left organisers with extremely red faces.