FORTUNE –When American Airlines declared bankruptcy around Thanksgiving of 2011, it seemed inconceivable that its shareholders would recover even a tiny sliver of their investment. Indeed, Wall Street wagered that the world’s biggest airline, sinking under $8 billion in debt, its stock and bonds both selling at a token 20 cents, wouldn’t even come close to repaying its bondholders, lenders, and the holders of its aircraft leases.
“Investors and pundits saw a dim future for American,” Tom Horton tells Fortune. Horton was CEO of AMR Corp., the parent of American and the executive who guided the airline through bankruptcy. He’s now chairman of the new American (AAL), which merged with US Airways in December. “It was all negative, especially for the stockholders. But our team didn’t believe that for a minute.”
Bankruptcy generally means a total flameout for shareholders — nowhere more so than in the bankruptcy-afflicted airline business. So the announcement on April 8 that the former American shareholders would recover a windfall of $11 billion, exceeding the airline’s total value at its peak by 18%, marked one of the most extraordinary, unexpected reversals in the financial annals of America’s airlines.
MORE: 6 great teams that take care of business
In an exclusive interview, Horton recounted two years of the arguments, posturing, and dealmaking that made that giant payout possible. “Even though we’d entered bankruptcy, we’d just ordered 450 new jets, and we had strong international alliances,” Horton remembers. “We knew we could be successful on our own once we got our costs and debt down, but we also thought a merger could work even better — once we got our own house in order.”
But Horton had barely gotten started, when, on April 20, 2012, Doug Parker, CEO of US Airways, proposed a merger in which his shareholders would own 50% of the combined carriers, with the American side, meaning its creditors, getting the other 50%. US Airways began its campaign arguing that the new American could never be successful on its own, that it needed a merger. And the market was buying it.
The American board dismissed Parker’s offer. But Parker won the support of American’s unions, creating strong momentum for a merger. Even then, Horton was mapping the best deal for his side, including the overlooked constituency, the shareholders. The creditors held the power to approve a deal with US Airways, and the banks and hedge funds cared about getting their own bonds and loans repaid, not salvaging the equity folks. “I wanted to take a bad set of dynamics and make it good. We did care about the shareholders,” says Horton.
MORE: eBay gets ‘even’ with Carl Icahn
Horton reckoned that a union with US Airways was probably inevitable. But to secure the best deal for his stakeholders, Horton needed to vastly improve on that 50-50 offer, especially given that American was the larger airline with a global footprint. The breakthrough came in persuading a creditors’ committee, composed mainly of hedge funds that held American bonds, to allow Horton to negotiate money-saving contracts with the union on his own. “Those creditors were convinced that if we presented our own restructuring plan, so that American could fly on its own, we could compare the value of the independent American to what US Airways was proposing,” says Horton. “That would get the maximum value for American, and ensure the maximum recovery for the bondholders who had all the power.”
Indeed, American surprised the naysayers by returning to profitability even in bankruptcy, raising Horton’s hopes for the shareholders. “The most important aspect of our recovery was how we performed during the restructuring, and credit goes to our people who stayed focused in a difficult and distracting environment,” says Horton.
The gambit worked. “We needed a different economic split,” says Horton. In November of 2012, Parker presented a new “split” that would grant 70% ownership in a merged airline to the old American stakeholders, and 30% to the owners of US Airways. American’s board countered by asking for 80% ownership. For a while, the deal hung in limbo.
Then, Horton and Parker came to the enlightened consensus that would ensure the merger’s success. They decided to tell the investment bankers to stop arguing over a point or two of ownership, and work together to clinch the labor deals for the merged airlines, which were not finalized, leading to a lot of uncertainty about their future costs. The two CEOs worked over Christmas and into the new year to create labor contracts ensuring that the new American would emerge with a competitive cost structure.
In January of 2013, Parker and Horton agreed to a split of 72% ownership for the American side, and 28% for the US Airways shareholders. “I was beginning to see a sweet deal for the equity holders,” says Horton. It appeared that the 70-plus percent ownership would fully repay bondholders, with money left over for the shareholders. At that moment, however, it was uncertain what the shareholders would receive, if anything.
Horton sought a solution that assured that his shareholders would participate in the upside, which he now saw as extremely promising. Horton told the creditors’ committee that he wanted 5% of the equity in the new American set aside for his former shareholders. “When I told the investment banker representing the creditors, you can imagine the silence on the other end of the line,” says Horton. “The notion wasn’t popular.”
MORE: Jamie Dimon says Fed stimulus exit will be easy
The creditors’ committee agreed to an allocation of 3.5%. In effect, the deal meant that, at a minimum, the old American shareholders would get 3.5% of the total value of the new airline, and the creditors would receive 68.5% — recall that Horton had negotiated a total share of 72% for his side. The creditors were agreeable for a simple reason: The new airline was looking so promising that their new shareholdings would easily recoup the credit extended to American, even after the 3.5% guarantee.
But Horton and his financial team wanted an additional twist. He proposed, and won, a mechanism that would give his shareholders a far bigger ownership split if the new American thrived after its stock market debut. The ownership escalator was based on the new stock’s performance during the new American’s first 120 days.
Here’s an example of how the formula worked. At $16 a share, the creditors would get back all of their $8 billion-plus, and lots of equity as well. The former American shareholders would receive double the 3.5% minimum bonus, or 7%, amounting to around $900 million.
But as Horton expected, the stock surged far beyond the value needed to repay bondholders, with a nice kicker left over. On Dec. 9, 2013, the first day of trading, new American’s shares opened at $24. When the valuation period ended on April 8, they’d surged to $36, a 50% increase. The escalation agreement raised the former American shareholders’ ownership to around 40%, or $11 billion. The bondholders still got a fat equity bonus, but the big windfall went to the folks who were supposed to get zilch.
“The reason it turned out that way was American started performing well even in bankruptcy, and the merger went smoothly,” says Horton, who also credits Parker’s foresight in “burying the knife” over the ownership-share negotiations to concentrate on securing valuable new labor agreements, and their subsequent work as a team to launch the new American. “I saw a huge pot of value,” says Horton. No news or numbers better symbolizes the optimism for America’s airlines.