SHANGHAI — China has gone on a spending spree, borrowing money to build cities, create manufacturing giants and nurture financial markets — money that has helped drive the economic powerhouse in recent years. But the debt-fueled binge now threatens to sap growth in the world’s second largest economy.

With its economy maturing, China has had to pile on ever more debt to keep growth going briskly, a pace that could prove unsustainable. And the money is increasingly flowing through opaque channels that operate outside the regulated banking system, leaving China vulnerable should those hidden risks blow up.

A major credit rating agency sounded the alarm on Wednesday, saying the steady buildup of debt would erode China’s financial strength in the years ahead. The agency, Moody’s Investors Service, cut the country’s debt rating, its first downgrade for the country since November 1989, five months after the Tiananmen Square crackdown.

China’s debt problems are drawing comparisons to Japan’s predicament. After a long, increasingly credit-backed boom, the bubble burst for Japan in the early 1990s. Since then, the Japanese government’s reluctance to deal with deeply indebted companies has contributed to decades of sluggish growth.