Suffering from slumping sales and mountains of debt, Toys 'R' Us has filed for bankruptcy.

The 69-year old Toys 'R' Us was once the mecca of kids' gifts. But it was eventually overtaken by Walmart and ultimately Amazon.

In its fight to stay relevant, Toys 'R' Us amassed $5 billion in debt. That came from slashing prices, signing major, exclusive licensing deals with toymakers and buying up other toy giants FAO Schwartz and KB Toys over the past decade.

At one point, Toys 'R' Us showed signs of a turnaround. After being taken private in 2005, Toys 'R' Us filed for an initial public stock offering in 2010. It ultimately withdrew its filing, citing "unfavorable market conditions."

Late Monday, Toys 'R' Us announced that it scrounged up $3 billion in bankruptcy financing, which it plans to use to restructure the company, alleviate its debt burden and revamp its stores.

The bankruptcy filing comes just ahead of the holiday season, the busiest time for the year for Toys 'R' Us. The company said it plans on keeping its 1,600 Toys 'R' Us and Babies 'R' Us stores open across the world, though the Wall Street Journal reported that the company will eventually close some of its underperforming locations as part of the bankruptcy process.

Toys 'R' Us noted in a press release that "the vast majority" of its stores are profitable. But the trend line is pointing in the wrong direction. The company reported that same-store sales fell by more than 4% last quarter, losing $164 million.

CEO Dave Brandon on Monday called the retail landscape "increasingly challenging and rapidly changing" but said he was confident that the Toys 'R' Us brand will "live on for many generations."

"Today marks the dawn of a new era at Toys 'R' Us where we expect that the financial constraints that have held us back will be addressed in a lasting and effective way," said Brandon in a prepared statement.

Related: Toys 'R' Us bankruptcy fears hit Mattel and Hasbro

Toys 'R' Us joins a list of hundreds of companies that have succumbed to the online threat and filed for bankruptcy protection this year. That includes the children's clothing store Gymboree, teen outlet Rue21 and Payless Shoe Source.

It closed its gigantic store in New York's Times Square at the end of 2015. It recently opened a temporary, smaller store for the holidays in another part of the popular Manhattan tourist spot though.

The troubles facing Toys 'R' Us aren't just about competition from Amazon (AMZN) and Walmart (WMT). A lackluster summer at the box office might be hurting the entire toy industry, which depends on hit movies to drive sales of licensed toys.

Toy companies also have to deal with the fact that many kids are increasingly playing games on consoles, phones and tablets and not with old-school action figures, dolls and other toys.

Even Lego has been struggling lately. Investors are worried that Mattel and Hasbro could be in trouble, too.

Mattel (MAT), acknowledging the threat from tech, recently hired a new CEO who used to be an executive at Google. Its stock dropped 6% on Monday, to its lowest level since 2009, and Hasbro (HAS) fell 1%. Each company relied on Toys 'R' Us for more than 10% of its sales in the most recent fiscal year.

- Paul R. La Monica contributed to this report