Philippine President Rodrigo Duterte was heading to China late Tuesday for a visit that was set to upend relations in the region and possibly throw a security challenge to Japan, which he is due to visit next.

The visit promises to end years of estrangement between Beijing and Manila, but elevating China as a security partner at the expense of ties with Washington could also weaken the military relationship Japan relies on.

Until recently, Duterte and Chinese President Xi Jinping seemed unlikely allies, given the miserable state of ties when Duterte took office. But on Tuesday Chinese state media welcomed the tone that he has adopted in the three months since then.