LOS ANGELES — Even before the fourth lead change of the fourth quarter, well before the 1,001st yard of combined offense was tallied, the Kansas City Chiefs and the Los Angeles Rams already knew this was a classic.

Two powerhouse NFL teams at the peak of their brilliance dueled deep into the night at an ecstatic Coliseum, racking up eye-popping numbers that stretched the box score and credulity.

There were 14 touchdowns, including three by defensive players. There were 56 first downs. There were 105 points, with 50 from each team — the first time that’s ever happened in an NFL game.

In the final moments, the Rams did just enough to leave with a win they’ll savor for years.

And if these teams meet again at the Super Bowl in 21/2 months, the Chiefs will remember the sting from coming up just short.

Jared Goff threw a 40-yard touchdown pass to Gerald Everett for the go-ahead score with 1:49 to play, and the Rams outlasted the Chiefs for a 54-51 victory on Monday night in a high-octane offensive showdown that somehow surpassed the hype.

“It was a crazy game, crazy game,” said Goff, who passed for 413 yards and four touchdowns. “It seemed like whoever had the ball at the end was going to win the game. There was times where we felt like we were going to put the knife in and finish them, and there were times where it was the other way around, where we had to claw back into it.”

Patrick Mahomes passed for a career-high 478 yards with six touchdown passes in his latest jaw-dropping effort for the Chiefs (9-2), but he also threw two interceptions in the final 1:18 as the Rams (10-1) claimed the highest-scoring Monday night game ever played.

The highest-scoring game in the league this season was an offensive fantasia of ingenious scheming from mastermind coaches Andy Reid and Sean McVay — along with 21 combined penalties to keep things interesting. The second half was an extended thriller featuring 59 combined points.

Both teams scratched out fourth-quarter leads, only to see them evaporate. Mahomes hit Tyreek Hill with a majestic 73-yard TD pass just when the Rams appeared to be pulling away early in the fourth, and Goff replied with two late TD passes to Everett, a backup tight end with 31 career catches before this game.

“It was a whirlwind,” McVay said. “I feel like I might need a couple of beverages to relax tonight, but it was great. This is what you love so much about the game.”