BEIJING (Reuters) - China's official news agency said in a commentary on Sunday that the shutdown of the U.S. government exposed "chronic flaws" in the U.S. political system.

Funding for federal agencies ran out at midnight on Friday in Washington after lawmakers failed to agree on a stopgap funding bill.

"What's so ironic is that it came on the first anniversary of Donald Trump's presidency on Saturday, a slap in the face for the leadership in Washington," China's Xinhua News Agency said in a commentary by Xinhua writer Liu Chang.

The commentary said that the Trump administration had "backtracked" on policies supported by his predecessor, Barack Obama, including the Trans-Pacific Partnership trade agreement and U.S. participation in the Paris climate agreement.

"If there was any legacy that has survived the transfer of power, it was the spirit of non-cooperation across party lines," the Xinhua commentary said.

While Xinhua commentaries are not official statements, they offer a reflection of Beijing's thinking.

"The Western democratic system is hailed by the developed world as near perfect and the most superior political system to run a country," it said.

"However, what's happening in the United States today will make more people worldwide reflect on the viability and legitimacy of such a chaotic political system," it said.

At a twice-a-decade congress of China's ruling Communist Party in October, President Xi Jinping was anointed for a second term as party chief, strengthening his grip on power.

(Reporting by Tony Munroe; Editing by Muralikumar Anantharaman)