On Wednesday, Philippine President Rodrigo Duterte said it was “time to say goodbye” to the United States. So on Thursday, he said a cheery hello to China.

In meetings that followed months of anti-U.S. rhetoric, Duterte and his Chinese counterpart, Xi Jinping, met at Beijing’s Great Hall of the People, promising to move from bitter fighting to close friendship..

The leaders did not reach a deal on the South China Sea, as some predicted, but did agree to bilateral talks — a striking turnaround for the Philippine side.

They also signed 13 agreements, cementing plans for closer cooperation on issues such as counternarcotics and fishing, and paving the way for a rush of Chinese infrastructure investment.

Lest the message be lost, Duterte later announced his country’s economic and military “separation” from the United States in a speech to business executives in Beijing, drawing applause from the crowd.

Americans are a “discourteous people,” with a “larynx not adjusted to civility,” he said, according to video shot by a Filipino journalist in attendance.

“I’ve realigned myself in your ideological flow,” Duterte told his Chinese hosts while suggesting he could eventually reach out to Russian President Vladi­mir Putin for talks on a three-way alliance, according to the Reuters news agency.

“There are three of us against the world — China, Philippines and Russia. It’s the only way,” Duterte added.

Thursday’s scene will give Manila and Beijing something to cheer about: Duterte can return home, cash in hand, having earned some international support for a self-proclaimed “drug war” that has claimed thousands of lives. 

Beijing’s top brass, meanwhile, get to court a cornerstone player in the U.S. rebalance to Asia, showing neighbors that it pays handsomely to play nice with China.

“This truly has milestone significance for China-Philippine relations,” Xi said.

Duterte, this time more poetic than potty-mouthed, spoke of a “springtime” for Sino-Philippine ties.

Not cheering: the United States.

“It is inexplicably at odds with the very close relationship that we have with the Filipino people, as well as the government there, on many different levels, not just from a security perspective,” John Kirby, the State Department spokesman, said Thursday.

U.S. diplomats, he said, would be seeking an explanation as to what exactly Duterte intends.

Duterte’s state visit, which coincided with the U.S. presidential debate, seems to signal a shift in the regional balance of power. 

In recent years, China’s claims to most of the South China Sea have pushed the Philippines toward Washington; Manila took Beijing to an international tribunal and made plans for more U.S. troops on Philippine soil.

In less than four months in office, however, Duterte has changed that trajectory. When the court issued a broad rebuke of China’s maritime issue, he played down the decision and instead made overtures to Beijing.

“I think he’s trying to find the balance that best benefits the Philippines,” said Xu Liping, an expert on China and Southeast Asia at the Chinese Academy of Social Sciences, in Beijing.

The new balance matters greatly to the United States. The Philippines is a former U.S. colony and a critical ally in the region — but those ties are now in question. 

In September alone, Duterte called for the withdrawal of U.S. Special Forces from the southern island of Mindanao, threatened to end joint maritime patrols with the United States and vowed to end annual military exercises. However, he made the comments before contacting American officials, leaving diplomats wondering where the rhetoric ends and the policy starts.

There does seem to be a gap between what Duterte says and what his government and allies hope to do. His comment about Special Forces in Mindanao, for instance, was quickly walked back by his defense secretary — and then by Duterte himself.

Duterte’s bombast and backtracking have bolstered the idea that he is ad hoc and impulsive. But Manila-based diplomats and scholars have characterized his comments as a shrewd negotiating technique, a way to butter up China without giving the United States the boot — yet. 

A sudden shift away from the United States would be a tough sell. The vast majority of Filipinos — and Duterte’s own allies — hold positive views of the United States. The foreign policy and defense establishment has worked with the Americans for years and relies to some extent on U.S. money.

“Are we throwing away decades of military partnership, tactical proficiency, compatible weaponry, predictable logistics and soldier-to-soldier camaraderie just like that?” former president Fidel Ramos, once a Duterte mentor, asked in a recent letter.

The confusion about Duterte’s plans have put Washington “on edge,” said Jay L. Batongbacal, director of the University of the Philippines’ Institute for Maritime Affairs and Law of the Sea, because the U.S. side “cannot see any reliable gauge of Duterte's foreign policy.” 

With the U.S. election looming, the task of calibrating a response will be left to the next administration. 

Eduardo Araral, vice dean and associate professor at the Lee Kwan Yew School of Public Policy at the National University of Singapore, said that Democratic presidential nominee Hillary Clinton, as an architect of the Obama administration’s rebalance to Asia, would need to make “respectful and conciliatory” overtures to Duterte — but would she? 

The effect of a win by Republican nominee Donald Trump is harder to gauge. “Trump might actually like Duterte,” he said. 

Xin Jin contributed to this report.