John McCarthy celebrates with the Philip F. Anschutz trophy after winning MLS Cup. (Jayne Kamin-Oncea-USA TODAY Sports)

You could not have scripted a better Hollywood ending.

Back-up goalkeeper John McCarthy, who had all of 90 minutes of league action under his belt this season, was forced into the MLS Cup final in extratime due to an injury and red card to regular keeper Maxime Crepeau.

McCarthy then rose to the occasion and then some in the penalty-kick shootout, making two saves to give the Los Angeles Football Club its first MLS championship. LAFC defeated the Philadelphia Union, 3-1, in the tie-breaker.

It was a dramatic and entertaining finish after the teams battled to a 3-3 deadlock after more than 120 minutes of nail-biting action in an epic encounter and one of the greatest finals in the 27-year history of the competition, at Banc of California Stadium on Saturday afternoon.

Both teams overcame one-goal deficits in a physical contest that was marked with a horrific collision in extratime.

In the 110th minute, Crepeau and crunched Philly’s Cory Burke, as the two went for the ball near the top of the penalty kick in the 110th minute. Crepeau slammed into and fouled Burke as both players fell to the ground. Crepeau, who reportedly suffered a broken bone in his foot, originally was yellow carded before he was slapped with a red card.

McCarthy replaced him in the 116th minute. Nine minutes of actual injury time was needed to compete the period.

That led to plenty of time for both teams to provide some late match heroics.

First, it was Philadelphia defender Jack Elliott scoring his second goal to lift the visitors to a 3-2 edge four minutes into second extratime added time.

Not to be denied, it was LAFC’s turn to pull off some dramatics as Gareth Bale, who had come on in the second half, scored eight minutes into stoppage off a Diego Palacios assist to knot things up at 3-3.

Then came the Crepeau incident that set up McCarthy as the unlikely hero. After Daniel Gazdag sent his attempt far into the stands, McCarthy denied Jose Martinez and Kai Wagner on Philly’s second and third tries.

Meanwhile, McCarthy’s teammates did their job. After Philadelphia goalkeeper Andre Blake saved Cristian Tello’s PK, Denis Bouanga, Ryan Hollingshead and Ilie Sanchez converted theirs to give the capacity crowd so much more to cheer about.

The victory capped a memorable, record-setting season for LAFC, which became the first Supporter Shields’ winner to win the MLS Cup a well since Toronto fC accomplished the feat in 2017. Only eight teams have completed the MLS double since the league started in 1996. Los Angeles completed the regular season atop the Western Conference with an impressive 21-9-2 mark and 67 points.

Carlos Vela was the lone LAFC performer to earn post-season honors as he was named to the MLS Best XI team.