With the clock winding down at the end of the first half, Katy Perry's Super Bowl halftime show was in deep trouble.

The production was saved at the last minute by an unlikely hero: Seattle Seahawks coach Pete Carroll.

As Sports Illustrated details, the coach's aggressive play-calling and decision to go for a touchdown instead of running out the clock was the difference between a successful halftime show and one that would have been ruined by a sun that hadn't quite set.

Perry's production was designed to be displayed against a dark sky. But the first half of Super Bowl XLIX was played at such a fast pace that the organizers realized they were on pace to perform while it was still bright out.

In fact, it seemed at one point that the show would most certainly be performed in the light. It took three scoring drives to stretch out the first half. The last critical drive -- started with 31 seconds left before halftime, and when the Seahawks could have easily kneeled down and gone to the locker room -- involved three timeouts and one stoppage in play.

Even then, the halftime crew barely made it.

"We made darkness by something like 25 seconds,” said Katy Perry's creative partner, Baz Halpin, to SI. "For months and months, I never panicked. Then the game was so fast -- how did we not think about the sun? It was a miracle."

Here is a detailed illustration from Sports Illustrated about how intricate the production was:

More: Katy Perry Is Now Selling A 'Left Shark' Adult Onesie For Of $130

Story continues below