They didn’t like the West’s playbook. So they wrote their own.

With a statue of Deng Xiaoping, who led the opening up of China in 1978, in the foreground, Shenzhen put on a light show last month to mark the 40th anniversary of those economic reforms. Lam Yik Fei for The New York Times

The Chinese thought they had little to learn from conventional wisdom. Now it’s the West that’s taking notes.

Milton Friedman had a message for China: To get rich, it must be free.

It was 1988. The Soviet Union was tottering. Across Eastern Europe, the communist order was on the verge of collapsing. Trying to avoid its own demise, the Chinese Communist Party had taken small steps toward unshackling its economy from the state. But prices for food and other necessities were surging as a result, and the party’s reformers wanted advice.

They invited Mr. Friedman — the Nobel laureate and champion of economic freedom — to Zhongnanhai, the walled compound in Beijing where the country’s most senior leaders live and work. Sitting down with Zhao Ziyang, the Communist Party’s top leader, Mr. Friedman was tactful but insistent. If Beijing wants to help its people thrive, he said, the state must let go faster.

“I hope the Chinese people can become strong and prosperous,” he told Mr. Zhao. “I wish to see China’s reform succeed so that she can contribute more to the progress of mankind.”

The economist Milton Friedman with his wife, Rose, in Beijing. He urged Chinese reformers in 1988 to loosen their control of the economy even more. A year later, tanks rolled into Tiananmen Square. Free to Choose Media

China made a different choice. Mr. Zhao and other reformists were ousted a year later. Tanks were sent to Tiananmen Square to teach the people a bloody lesson about challenging the party’s power.

China would instead reform on its terms. It would free entrepreneurs to seek their fortunes, while still keeping a tight grip on essential economic levers. It would set national goals, then persuade or force people and companies to meet them. It would open up to the world at its own pace — and the Communist Party would run the show.

How China became a superpower

To Mr. Friedman and other top economists, the strategy should have failed. Centrally planned economies breed waste and corruption. Big government ambitions cripple future generations with debt. Price controls lead to hunger and want. Official prognosticators invariably blow it. The Soviet Union proved that.

Those experts were wrong. China prospered.

A subway station in Shenzhen, which Mr. Deng visited in 1992 during a tour to promote his case for a “socialist market economy.” Lam Yik Fei for The New York Times Lunchtime at a restaurant in Shenzhen. It’s a city where a penniless carpenter like Shao Chunyou could arrive three decades ago and end up a successful entrepreneur. Lam Yik Fei for The New York Times

Today it is the world’s second-largest economy. Hundreds of millions of its people have been lifted out of poverty. It is home to the world’s biggest auto industry, the second-most billionaires and the largest single group of internet users. It has some of the richest and most powerful technology companies on the planet.

China succeeded by creating its own model. It borrowed some Western ideas while rejecting others. It opened itself to the world when necessary, and put on the brakes when it chose to. It set goals and backed them with government money. It freed its people to make and spend money, but it forbade them to ask for a better deal. Entrepreneurs built modern China, and the Communist Party kept them in line.

Other potential success stories in Asia and Latin America stuck to the economic script and stumbled. They slashed budgets when international experts told them to, hurting growth. They opened up to the world before they were fully ready to compete — and were tripped up by global turbulence. China’s government, by contrast, reformed slowly and sometimes reluctantly, stepping in when external or internal forces threatened its rule. During financial crises that struck Asia in 1997 and then the world in 2008, China gained strength as other nations faltered.

China’s economy now stands as an alternate narrative to Western ideals. And yet the decisions the Communist Party made to secure its economic future have led Beijing to its biggest test since Tiananmen Square.

Its goals — a complicated mix of juicing the economy, cleaning up the country’s air and water and meeting its people’s rising expectations — have become harder to reach. Its efforts to spur growth have left the country staggering under trillions of dollars in debt, while the world is taking aim at China’s industrial ambitions.

And after three decades of balancing freedom and authoritarianism, China may be leaning too far toward state control under Xi Jinping, the country’s top leader. The Communist Party may be putting too much stock in its own abilities at the expense of the entrepreneurs who drove China’s success.

Milton Friedman might have been right after all.

Or China may still find its way.

Over and over, China has been underestimated by legions of leaders and economists who thought they knew better. “It’s not only the West,” said Justin Lin Yifu, a former chief economist at the World Bank, who was born in Taiwan but defected to China. “It’s almost every country in the world. It’s the multilateral institutions and the academics and intellectuals.”

A Booming Bird Cage

Deng Xiaoping, the paramount leader of China, was worried. After the 1989 Tiananmen Square crackdown, his great Chinese experiment faced collapse.

He had led the country out of the chaos of the Cultural Revolution under the idea that its people should make more money. Farmers were given greater choice to plant what they liked and sell it for a profit. Entrepreneurs flocked to special economic zones, essentially capitalist petri dishes where they paid lower taxes and made their own business decisions. The economy surged, millions of people were lifted out of poverty, and China’s growth become the envy of the world.

Student demonstrators in Tiananmen Square in 1989, before the government crackdown. S. Mikami/Associated Press

The boom, though, fostered inflation and corruption. When the tanks rolled through Tiananmen Square, they killed not just pro-democracy activists but also common people angry at surging prices for rice, vegetables and vinegar. The reformers were ousted, and the conservatives who took their place reasserted state control.

By 1990, foreign investors were fleeing and some Communist Party cadres were again suppressing entrepreneurs. Growth had fallen to one-third that of the boom years. Deng feared that, without a spark, the Communist Party would lose its control over China. Reform, he decided, had to be on the agenda again.

Finding the right balance would prove the economic foundation of modern China. Loosen the grip too much, and the Communist Party begins to face a real threat to its hold on power. Tighten too much, and it threatens to squelch the country’s growth.

Reform has swung in one direction or the other, but it has long fit into the model of what one of the architects of modern China, Chen Yun, called a “bird cage economy.” Entrepreneurs were free to spread their wings, as long as they stayed within the cage of government control.

A billboard of Mr. Deng in Shenzhen. In 1992, he warned of “a dead end” if China did not “carry on with ‘reform and opening’ and economic development.” Lam Yik Fei for The New York Times A crowd during Shenzhen’s celebration last month. Lam Yik Fei for The New York Times

In 1992, Deng embarked on his “southern tour” — a visit to Shenzhen and other emerging capitals of Chinese commerce. He laid out the case for a “socialist market economy” that would twin an embrace of markets with respect for the Communist Party.

“If China does not practice socialism, does not carry on with ‘reform and opening’ and economic development, does not improve the people’s standard of living, then no matter what direction we go,” he said, “it will be a dead end.”

He championed the lessons of people in Shenzhen like Shao Chunyou. Mr. Shao, now a successful entrepreneur who owns an electronics manufacturing company, was one of the hundreds of millions of Chinese who struck a silent pact with his country to pursue riches while staying out of the state’s business.

The crackdown in Tiananmen Square was far from Mr. Shao’s mind when he arrived that summer in Shenzhen. A penniless carpenter from a city in China’s interior, he struggled to find work among the electronics factories and garment mills. He wasn’t allowed to live in Shenzhen without a government permit, so when the police came looking for illegal workers he would hide in a cemetery. Once, he lived off discounted mooncakes after China’s Mid-Autumn festival holiday.

“I still can’t bear looking at mooncakes,” he said.

Three years later, in 1992, Mr. Shao was earning more money at a factory making hardware parts for electronics than he had ever made before. Such successes would cement the country’s path.

Conservative leaders were sidelined for reformers. Local officials loosened up, and banks started lending. China abolished ration coupons for food and drastically reduced the government’s role in setting prices for grain, oil and coal. China’s entrepreneurs responded. Growth surged into double digits.

Two years later, the International Monetary Fund and other leading economic institutions publicly worried that China’s growth was too fast and threatened to spiral out of control. But the lessons from past failures taught China’s leaders to complement their reform efforts with aggressive government action at certain moments.

The leadership forced down prices of essentials like grain, eggs, vegetables and real estate. Even as it pressured bloated state-owned companies to streamline, it often gave them breathing room. Then, when prices fell, China gave a variety of industries — everything from tractor and electronics factories to ostrich breeders — the power to form cartels to stay in business.

The approach worried free-market economists. While they widely acknowledged that China couldn’t change overnight, they argued that state control hobbled the economy by pouring money into wasteful targets.

Mr. Friedman, the Nobel laureate, gave voice to those concerns when he returned to China in 1993. China’s entrepreneurs, he noted approvingly, were thriving. But everywhere, he saw the domineering presence of the Chinese government. “Not surprisingly,” he wrote later, “the managers of state-owned enterprises are not at all willing to give up their powers.”

Mr. Friedman was shocked at the scale of a government-led project to build what was in effect a new city, Pudong, across the Huangpu River from Shanghai. “A Potemkin village built for a reigning emperor,” Mr. Friedman wrote, predicting disaster.

A decade later, Pudong was one of Asia’s hottest real estate markets.

Opening and Dragging

While China was getting richer, it wasn’t enough by the end of the 1990s. It was still home to about one in five of the world’s poorest people. Inflation ping-ponged, demanding constant government attention. Beijing pushed state-owned companies to get leaner and work smarter, leading to the layoffs of millions of workers.

China needed growth. To get there, the leadership reasoned, it had to join the World Trade Organization, the premier global commerce club. Membership would mean lower tariffs for China’s manufacturers and give foreign companies the confidence to invest more in the country. Membership would also free China from the annual scrutiny that American lawmakers gave its human rights record before extending favorable trading terms.

Migrant workers eating lunch outside a construction site in Beijing in 1997, when China was home to about one in five of the world’s poorest people. Greg Baker/Associated Press

The rest of the world expected that China would be forced to adopt greater political and economic freedoms to compete. “The more China liberalizes its economy, the more fully it will liberate the potential of its people — their initiative, their imagination, their remarkable spirit of enterprise,” President Bill Clinton said in 2000.

Casting aside wasted years of halfhearted negotiations, China launched an all-out effort to get in. It yielded on a number of demands made by the United States and others. It agreed to slash tariffs and lower trade barriers to telecommunications, the financial sector and a host of other industries. It agreed to curb subsidies.

In the bargain, China got what it wanted, paving the way for a global trading colossus.

After China’s entry in the W.T.O. in 2001, its exports doubled in three years and nearly tripled in four. Investment poured into the country. Global manufacturers moved entire operations to China, while consumers around the world got cheaper tools, toys and phones.

Membership in the World Trade Organization was expected to force China to adopt greater political and economic freedoms. Lam Yik Fei for The New York Times Baishizhou, a village within Shenzhen, has been a source of cheap housing for immigrants. Lam Yik Fei for The New York Times

“When China joined the W.T.O., I was so excited that I cried,” said Zhu Dingding, the general manager of Hangzhou Jinyuan, which makes baby shoes and other crafts.

By 2011, orders were 10 times what they had been in 2001. He made enough money to buy a car, a Volkswagen. Three apartments followed, all purchased without mortgages.

“The W.T.O. pushed my business to develop rapidly,” Mr. Zhu said. “Without the W.T.O., it would be impossible.”

But China didn’t change that much.

Beijing has kept its iron grip on critical levers of the economy. It has been slow to meet commitments to open up key parts of its financial system, while other essential areas like telecommunications remain cut off. It has continued to nurture businesses aimed at meeting its technological and political goals, like high-speed rail and solar panels. It hasn’t fully relaxed its grip on the value of the country’s currency.

China’s entry into the W.T.O. caused a systemic shock, one underestimated particularly by the United States. Cheap Chinese goods ushered in a new era of low prices, upending industries from textile mills in South Carolina to circuit board manufacturers in Japan and fashion designers in Italy. One study suggested that, between 1999 and 2011, Chinese imports eliminated one million American manufacturing jobs, plus more in other industries.

“China’s entrance into the World Trade Organization has enabled the greatest jobs theft in the history of our country,” Donald J. Trump said at a campaign appearance in 2016, four months before he was elected president.

‘Can China Save the World?’

As the global financial system tottered in 2008, an influential Chinese leader chastised Henry M. Paulson, then the United States Treasury secretary and a former Goldman Sachs executive.

The leader, Wang Qishan, was among the first Chinese officials to soak in the lessons of the free market evangelists. But he told Mr. Paulson that China had perhaps listened to the West long enough.

“You were my teacher, but now here I am in my teacher’s domain, and look at your system, Hank,” Mr. Wang said, according to Mr. Paulson. “We aren’t sure we should be learning from you anymore.”

Treasury Secretary Henry M. Paulson with Vice Premier Wang Qishan of China in 2008. “We aren’t sure we should be learning from you anymore,” Mr. Wang told him. Jonathan Ernst/Reuters

Nobody was unscathed by the global financial crisis. Washington bailed out Wall Street and Detroit, then its efforts slowed to a crawl as a new president, Barack Obama, clashed with Congress over the size of a stimulus package. Europe also fell into squabbling as individual countries fell into crisis, creating cracks in the union.

While China withstood the initial shock, the ripples threatened to become devastating. Exports plunged and economic growth slowed as foreign markets dried up. Factories began to lay off workers. Later, economists at the World Bank would estimate that as many as 36 million Chinese workers had lost their jobs.

What followed was perhaps the greatest show of financial firepower the world has ever seen — and it wouldn’t have been possible without government controls that would have made Milton Friedman blanch.

Beijing unleashed a nearly $600 billion spending package in an effort to rev up its economy. It called for building rail lines, highways, power lines and other big infrastructure projects across the country.

Huaqiang has become an electronics manufacturing hub in Shenzhen. Lam Yik Fei for The New York Times Outside a Huaqiang shopping mall, workers loaded goods into a truck . Lam Yik Fei for The New York Times

Then it began to lend. The central bank flooded the country with money, and China’s economic leaders told its government-backed banks to start giving out loans. State-run companies were told to build and invest, and local government officials were told to help them. By one estimate, the financial stimulus totaled, over three years, nearly $1.4 trillion.

Asked one headline, “Can China Save the World?”

In some ways, China was well positioned for this moment. Early in its embrace of capitalism, it recognized the treasure it had in the savings of its people. Currently, their savings rate is nearly three times that of the United States — driven in part by worries that an underdeveloped social safety net won’t help them when they retire or get sick.

Because the government controlled the banking system, it could force banks to extend mercy to troubled borrowers or simply roll over their loans at more agreeable terms. It could ignore the advice of global investors and institutions, like the International Monetary Fund, that preached open markets and austerity, sometimes to disastrous results.

China also kept money from leaving the country. It put limits on how much people could move overseas and kept a tight grip on the value of its currency, the renminbi.

The contrast between China and the rest of the world was stark. Beijing moved swiftly — and its growth was the rare bright spot in the global economy. Washington didn’t complete a $787 billion stimulus package until the next year, filled with political compromises. The American economy couldn’t avoid recession.

Nicholas R. Lardy, a China expert at the Peterson Institute for International Economics, told American officials in 2009 that “China is the gold standard in terms of its response to the global economic crisis.”

Testing China’s Model

More than a quarter-century after Deng Xiaoping used his southern tour to get Chinese reform back on track, Xi Jinping followed on a mission of his own.

Mr. Xi’s trip to Guangdong Province in the south last month deliberately echoed his predecessor’s. Like Deng, he visited start-ups, inspected their work and gabbed with factory employees. He visited an appliance company and an auto parts plant, praising the role of small businesses in the Chinese economy. China, he said, hadn’t wavered from its commitment to them.

Mr. Deng in Shenzhen in 1992. China’s current leader, President Xi Jinping, has swung the pendulum back toward state control of the economy. Agence France-Presse — Getty Images

“China’s reform and opening up will never stop,” Mr. Xi told a group at an exhibition center celebrating decades of reform. “The next 40 years of China will bring new achievements that will make the world take notice.”

So far, Mr. Xi’s rhetoric hasn’t matched reality. While Deng dragged the Chinese economy further out of the clutches of state control, Mr. Xi has been pulling it back.

Despite calls to rein in debt, he has kept the money flowing. Despite a push to create global technology champions, he has put the country’s vibrant internet industry under the increasing authority of the party and the state. Despite promising to lift entrepreneurs, he has strengthened state behemoths, which now account for growing shares of the country’s profits and industrial production.

Mr. Xi has made some modest reforms. He has loosened, just a bit, Beijing’s hold on the value of its currency. He moved to allow foreign banks and automakers to directly own their Chinese operations.

But the pendulum has markedly swung toward the state at a time when the cumulative weight of four decades of choices has left the Chinese economy vulnerable. Growth is slowing — and juicing it won’t be as easy.

Beijing unleashed a major spending package to rev up its economy. It called for constructing rail lines, highways, power lines and other big infrastructure projects across the country. Lam Yik Fei for The New York Times China succeeded by creating its own model. It borrowed some Western ideas while rejecting others. The view from a skyscraper in Shenzhen. Lam Yik Fei for The New York Times

The lending-and-spending binge that powered its economy, and arguably the world’s, after the financial crisis has saddled the country with a huge debt load. While calculating what China owes is difficult since much is off the books, debt could total $41 trillion — or three years’ worth of the country’s economic output. That’s roughly equal to developed countries like the United States, Britain and Japan. But whereas their debt built up over decades, China’s accumulated in nine years.

Moving the needle has become harder. China’s economy is roughly three times the size it was in 2008. Those airport and highway projects it still uses to spur growth are expensive and deliver less economic bang.

The world has also begun to take aim at China’s pace of opening up and its global ambitions. President Trump has started a trade war over China’s economic barriers and its state-sponsored plans to build world-beating competitors in industries like semiconductors, robotics and electric cars.

The tariffs and tensions threaten a key cog in China’s trade machine: exports of goods and services, which total about one-fifth of the country’s output. The United States has also taken more forceful action against Chinese companies that it believes break the global rules of trade, in some cases depriving them of buying or investing in the American-made technology they need to survive or innovate.

And in a fundamental change, China’s leaders appear to be losing their willingness to experiment. Amid fear over slowing economic growth and difficult social problems, the party’s talk has turned to more control. Some increasingly strident voices within the Communist Party are tapping pre-reform language to lash out against Western ideas. Even private business ownership — a bedrock of Deng’s reform and opening up — has been criticized in some quarters.

China may also have become complacent. Its four decades of success under the China model may have persuaded the country’s leaders that the Communist Party, rather than the country’s entrepreneurs, drove its success, and it has little reason to let go.

“The China model concept misleads China,” said Zhang Weiying, a prominent pro-market economist, “so we’re going backward.”

China, of course, has changed course in the past. Pragmatism has often won out.

China’s leaders received a subtle reminder of that in September — from a son of Deng, the architect of reform. In a speech to top leaders, Deng Pufang praised their work but cautioned that once China’s opening had begun, it could never go back.

“Reform and opening up is the liberation of people,” he said. “It encourages the recognition of people’s desire and pursuit of a happy life, it stimulates the wisdom and strength of the masses, and it provides opportunities and platforms for every ordinary person to improve their lives and change their destiny.”