The new three-way security pact sealed by President Biden and the leaders of Japan and South Korea at Camp David on Friday was forged with threats by China and North Korea in mind. But there was one other possible factor driving the diplomatic breakthrough: Donald J. Trump.

While the former president’s name appeared nowhere in the “Camp David Principles” that the leaders issued at the presidential retreat, one of the subtexts was the possibility that he could return to power in next year’s election and disrupt ties with America’s two closest allies in the Indo-Pacific region.

Both Japan and South Korea struggled for four years as Mr. Trump threatened to scale back longstanding U.S. security and economic commitments while wooing China, North Korea and Russia. In formalizing a three-way alliance that had long eluded the United States, Mr. Biden and his counterparts hoped to lock in a strategic architecture that will endure regardless of who is in the White House next.

“This is not about a day, a week or month,” Mr. Biden said at a joint news conference with Prime Minister Fumio Kishida of Japan and President Yoon Suk Yeol of South Korea. “This is about decades and decades of relationships that we’re building.” The goal, he added, was to “lay in place a long-term structure for a relationship that will last.”