On December 27, 1996 Marvel filed for bankruptcy in U.S. Bankruptcy Court. The company was losing money hand-over-fist. Worse, it owed money (coincidentally, its highest debt, $1.7 million, was owed to Disney). Over one-third of Marvel employees were laid off. For a company that had created some of the most iconic and recognized characters the world over, the future seemed bleak.

This may seem hard to believe for a company about to release Avengers: Age of Ultron, the sequel to a film that grossed over $1.5 billion, and a studio whose lowest grossing movie (Captain America: The First Avenger) still brought in $370 million worldwide. So, how did Marvel scratch and claw all the way from the bottom to the top? They risked everything.

Bankruptcy paid off all existing debts, but if Marvel was going to survive, they needed to start actually making money. Marvel had grand new plans to create “Marvel Mania” theme restaurants, Marvel Interactive CD-ROMs and a new trading card initiative with Skybox. Marvel Mania opened one location in 1998 and closed a year later. The CD-ROM and trading card plans were woefully out of date before they were even announced. This was the kind of dated thinking that got Marvel into this mess.

If the Marvel Studios plan failed, they would lose the rights to every single one of those properties. The bank would own them and the plans for a Marvel Cinematic Universe would be dead.

The 1996 bankruptcy came two years before the first modern Marvel movie, Blade, hit theaters. While most of their other plans failed miserably, Blade was part of an ambitious licensing deal that sold the cinematic rights to properties like X-Men and Spider-Man to studios like 20th Century Fox and Sony Pictures for quick cash. It was a great idea on paper. Blade was a modest success, Bryan Singer's X-Men helped relaunch the modern era of superhero movies and Sam Raimi's Spider-Man grossed over $400 million. Those Marvel movies began to make a lot of money, except they were making money for everyone but Marvel.

Blade made $70 million at the U.S. box office, but Marvel only pocketed a shocking $25,000. Because of a flat-fee negotiation, Marvel made nothing off the success of X-Men.

In 2003, Endeavor talent agent David Maisel pitched Marvel a simple, but radical idea: why continue to give away your best assets to other companies for a paltry fee? Create your own production studio, develop and produce these titles in house and retain 100% of the profits.  At the time, Marvel was intrigued but hesitant to move forward. After about seven years toiling away at profitability in the wake of their bankruptcy, they were finally starting to see some returns, as small as they were. Why risk all that on a plan that leave them broke again?

Maisel was persistent; his main argument was that if this deal failed they were arguably no worse off than where they currently were, but with a chance to become their own successful studio and finally in creative and financial control of their own assets. In 2005, the Marvel board approved Maisel's plan and a seven-year, $525 million financing deal with Merrill Lynch was announced that would launch Marvel Studios, an internal production company that would “give Marvel complete creative control” over their films (an agreement was reached with Paramount Pictures who would market and distribute the films).

But, to get that $525 million, Marvel had to put something up as collateral: almost everything they had.

The deal included 10 properties — Captain America, The Avengers, Nick Fury, Black Panther, Ant-Man, Cloak & Dagger, Doctor Strange, Hawkeye, Power Pack, and Shang-Chi — and if the Marvel Studios plan failed, they would lose the rights to every single one of those properties. The bank would own them and the plans for a Marvel Cinematic Universe would be dead.

It was an incredibly risky move. Marvel knew, even at this early point, that they wanted to build towards an Avengers movie, and if this deal failed, they'd lose that opportunity. There would be no Avengers and we'd never see Captain America: The First Avenger, Black Panther, Ant-Man or Shang-Chi (OK, we were never going to see a Shang-Chi movie anyway).

If Marvel's plan didn't succeed, and succeed right away, they were right back to square one and with no more movie rights left.

That put a lot of pressure on whatever Marvel's first film would be. And if they got to this point with a lot of shrewd planning, they'd also need a little luck.

That initial list of Marvel films includes a lot of familiar faces, but is missing one of their biggest names: Iron Man. At the time, Iron Man was still owned by New Line Cinema (a subsidiary of Warner Bros.), but their option ran out and just two months after the above deal was announced, Marvel got the rights back to the character. But, because Iron Man was not part of their financing deal, they could not use the money they acquired to make that film. Marvel wanted to launch their films with a character who had never been in live-action before so, in another huge gamble, they fully financed the first Iron Man film themselves, with their own money.

The rest is, as they say, history. The risk Marvel took in putting up The Avengers as collateral on their new studio worked. Iron Man made over $500 million and Marvel has never looked back, eventually selling to Disney for $4.3 million in 2014. (For his efforts, Maisel has a special “thank you” card at the end of Avengers: Age of Ultron.) Meanwhile, Shang-Chi is waiting patiently for his own movie.

More From ScreenCrush