While Washington wasn’t looking, democracy won a major battle over authoritarianism in Malaysia, a Muslim-majority nation that just voted out its crooked, illiberal leader and has embarked on a peaceful transition to a new era of hope. The unexpected change has given the Trump administration a chance to reverse a policy of benign neglect toward the region, support democracy — and gain a rare win over China.

The United States had little to do with last month’s overwhelming election victory by a multiracial, multiparty opposition coalition in Malaysia. Their popular movement overcame huge obstacles imposed by the now-ousted regime of Prime Minister Najib Razak , who merged gross corruption and cronyism with racial division and antidemocratic repression. Both President Trump and President Barack Obama bought into Najib’s pitch that he was a good security partner while largely ignoring his abuses — including the jailing of opposition leader Anwar Ibrahim on politically motivated charges.

After spending more than 10 years in prison over multiple stints, Anwar was released following the May vote. Even before he left jail, though, he formed an alliance with the man who originally put him there, Prime Minister Mahathir Mohamad. Together, they are determined to set Malaysia on the right path. Mahathir, 92, has pledged to hand over the prime minister’s position to Anwar after a transition period.

During an interview, Anwar told me that after 20 years of sustained struggle, his movement has proved that peaceful resistance can result in positive change. He credited the “wisdom of the masses,” who, if properly informed and given a fighting chance, will ultimately come down on the side of universal rights, pluralism, integrity and freedom.

“You give the people information and hope and finally they will come down on your side,” he said. “A revolution transferred to the ballot box. This is a remarkable feat in a democracy.”

Mahathir and Anwar have no illusions about the difficulty of their task ahead. They are moving smartly but cautiously to consolidate power, form a new government, solicit buy-in from Malaysian institutions, and to keep their movement from either succumbing to an excess of reformist zeal or sliding back into the bad habits of past rulers.

Anwar’s status as a politician with deep Islamist roots worries some in Washington that he could follow the pattern of other recent attempts to combine Islamist politics with democracy. In Egypt, a duly elected Muslim Brotherhood-led government abused power and was deposed. In Turkey, an Islamist party maintains power but has become deeply illiberal. Anwar says he is committed to democratic principles and is conscious of the mistakes of the past.

“The case in Egypt is a lesson to us, which means you can’t impose a structure that’s deemed as a shock,” he said. “We have to be cautious, but we must progress. No way should we return to the old order.”

The U.S. government could help the new Malaysian government to dig out of the mess that Najib left by helping it reform civil society, return to a free press and bolster the country’s economy. The United States can also help recover the billions Najib’s clique plundered from Malaysian coffers. The U.S. Justice Department is already deep into its investigations of those scandals.

“It is a great victory for democracy,” said John Malott, a former U.S. ambassador to Malaysia. “Now we just need to do everything we can to help them carry it through.”

There’s also a key opportunity for the United States to score a rare victory over China in Asia — one the Trump administration didn’t intentionally pursue. Mahathir has either paused or canceled several major Chinese-funded investment projects amid allegations of kickbacks to Najib and predatory deal terms. Beijing was heavily invested in Najib, and the Malaysian people resent it.

Anwar said the new Malaysian foreign policy will be more diverse, seeking good relations with all neighbors and big powers alike. The United States must offer a more attractive, stable and sustainable package of cooperation to counter China’s heavy-handed approach.

Washington must also give Malaysia room to pursue an independent foreign policy while it figures out its path forward. The new government intends to continue cooperation on counterterrorism, counternarcotics and intelligence-sharing. But don’t expect Malaysia to agree with the Trump administration on issues such as climate change or the status of Jerusalem.

The other faux democracies or semi- ­autocracies in Southeast Asia must be eyeing Malaysia’s recent turnover nervously. Anwar warns that Malaysia’s is not necessarily a model that can be replicated in countries with different political landscapes.

But in a world where authoritarianism is on the rise and corrupt rulers act with impunity, Malaysia has now shown that organized, informed populations determined to reassert their rights can still turn the tide.

The idea that democracies are fragile and cannot work is now debunked, Anwar said. “That argument can no longer sustain itself. In Malaysia, we have proven it can work.”