When a company is on the brink of failure, it will often file for Chapter 11 bankruptcy protection. This allows the company to undergo a reorganization of business affairs, its debts, and its assets. Many companies that go bankrupt are able to settle with their creditors and then close up shop permanently.

Enron, Worldcom, and Lehman Brothers are just some well-known examples of bankrupt companies that never came back. On the other hand, some companies have managed to re-emerge from bankruptcy in better shape than before they went bust. (For more, see: What You Need to Know About Bankruptcy.

Below is a list of some of the most spectacular comebacks from companies that either went bankrupt or came nail-bitingly close to doing so.

Apple 

It is hard to believe that the world's largest company by market capitalization was once in dire straits. While never actually filing for bankruptcy, Apple (AAPL) was on the verge of going bust in 1997. At the last minute, arch-rival Microsoft (MSFT) swooped in with a $150 million investment and saved the company. People have speculated that Microsoft only did so because it was worried that regulators would regard it as a monopoly without the competition from Apple in the marketplace. 

General Motors 

Following the financial crisis of 2008 and the Great Recession, General Motors (GM), once the largest automobile manufacturer in the world, filed for bankruptcy and was ultimately bailed out by the federal government. In December 2013, the U.S. Department of the Treasury fully exited its investment in GM, recovering a total of $39.7 billion from its original investment of $51 billion.

Ally Bank

Ally Bank, now Ally Financial (ALLY), was the auto-financing arm of General Motors, extending credit to purchasers of its cars. The bank was bailed out alongside its parent to the tune of $17 billion by the U.S. Treasury Department. The company has emerged as a profitable business with a market capitalization of $11.9 billion.

Chrysler 

General Motors wasn't the only car maker to go bust in 2008. American car manufacturer Chrysler was actually the first to fall. Despite a $4 billion government bailout package, the company was forced to declare bankruptcy in 2009. It was later purchased by European car maker Fiat (FCAU) and has seen above average success and growth since. 

Marvel Entertainment

With blockbuster movies such as Spiderman, The Avengers, and Guardians of the Galaxy, it is surprising to note that Marvel filed for bankruptcy in 1996. This was before the company got into the movie-making business when it focused primarily on comic books. Today, the company's properties are worth billions of dollars with millions of fans around the world and it is now a subsidiary of Disney (DIS).

Six Flags 

Theme park operator and amusement company Six Flags (SIX) has 18 regional theme and water parks throughout North America, home to some of the world's biggest and fastest roller coasters. In 2009, however, the company declared bankruptcy after racking up more than $2.5 billion in debt which it could not pay back. Six Flags reorganized and emerged from bankruptcy in 2010.

Texaco

Now part of Chevron (CVX), Texaco was once one of the most dominant integrated oil companies in the world. A legal dispute with competitor Pennzoil over the purchase of Getty Oil in 1984, however, caused it to file for bankruptcy. The court ordered Texaco to pay$11 billion to Pennzoil, which Texaco couldn't. It emerged from bankruptcy and agreed on a $3 billion payment with Pennzoil.

Sbarro

Sbarro operates and franchises more than 800 fast-food style pizza and Italian-food restaurants worldwide. Sbarro went bankrupt twice: first through a Chapter 11 bankruptcy reorganization in 2011 and then again in 2014. The company has re-emerged with the help of a collaboration of private equity firms to transform the company's image to a more fast-casual style, rather than its previous kiosk or food counter concept.

The Bottom Line

Bankruptcy is often the end of a company, but it doesn't have to be in every case. The companies in the list above have re-emerged from bankruptcy to become profitable and successful. As an investor, it is useful to note that bankruptcy isn't always the end of the line for a company and that through buying shares of companies as they emerge from bankruptcy, reorganization can be a potential source of excess returns.