NEW DELHI — Over four nerve-racking nights, missiles and drones streaked across the skies of major cities in India and Pakistan, as the nuclear-armed neighbors appeared to be sliding toward all-out war. Then, seemingly out of nowhere, President Donald Trump announced a truce.

“India and Pakistan have agreed to a FULL AND IMMEDIATE CEASEFIRE,” Trump posted to Truth Social on Saturday, saying a deal had been reached after a “long night of talks mediated by the United States.”

The sudden announcement of a U.S.-brokered ceasefire followed four days of steady escalation between the regional rivals, and mixed signals from Washington over whether it would reprise its traditional role as mediator.

Amid celebrations in India and Pakistan on Saturday, and self-congratulations in Washington, Kashmir endured another night of violence, with both sides claiming violations — a grim reminder that the deal seems only to have temporarily contained one of the world’s longest-running conflicts rather than ending it.

A person familiar with the situation, who like others in this story spoke on the condition of anonymity to discuss sensitive negotiations, said Vice President JD Vance called Indian Prime Minister Narendra Modi around noon in Washington on Friday after senior U.S. officials became increasingly worried about the spiraling situation.

The person said Vance provided Modi with a potential “off-ramp” that U.S. officials understood Pakistani officials would be willing to accept. Over the next 12 to 18 hours, key U.S. officials worked the phones with counterparts on both sides, the person said.

Secretary of State Marco Rubio spent much of Friday night going back and forth between senior Indian and Pakistani officials to seal the deal, according to a senior U.S. official.

“We commend Prime Ministers Modi and Sharif on their wisdom, prudence and statesmanship in choosing the path of peace,” Rubio posted Saturday on X, adding that Vance had joined him in the efforts.

The role of the vice president was especially surprising, coming just a day after he had seemed to dismiss the possibility of a U.S. diplomatic intervention: “We’re not going to get involved in the middle of a war that’s fundamentally none of our business and has nothing to do with America’s ability to control it,” Vance told Fox News on Thursday.

“We can’t control these countries,” he added.

Islamabad was quick on Saturday to acknowledge the U.S. role. One Pakistani official said the agreement rested on two factors: “One is the serious risk of escalation, and second, the White House administration — the external intervention.”

“We should give the credit where it is due,” the official added.

“De-escalation has ultimately come through the old playbook: the third party actors, led by the U.S.,” Moeed W. Yusuf, a former national security adviser for Pakistan, posted on X.

Indian officials were less forthcoming about the American role. Some commentators in New Delhi openly took issue with Rubio’s claim that India had agreed to “talks on a broad set of issues” with Pakistan; others pointed out that India has traditionally been opposed to third-party mediation on the disputed territory of Kashmir, preferring to handle the issue bilaterally.

But it was not the first time the U.S. has helped dial down tensions between the South Asian powers. In July 1999, President Bill Clinton hosted Pakistani Prime Minister Nawaz Sharif in Washington at the height of the Kargil War and pressured him to withdraw his forces from Indian-administered territory.

U.S. diplomatic efforts seemed to gather pace on Thursday, when Rubio spoke with Indian Foreign Minister S. Jaishankar and Pakistani Prime Minister Shehbaz Sharif.

On the ground, though, the conflict was still heating up, as the countries exchanged strikes on military sites overnight Saturday.

It was then that Rubio reached out to Pakistani Army Chief Gen. Asim Munir, according to officials in Islamabad.

“I’d say what made the difference was Rubio’s conversation with Munir,” said Indrani Bagchi, the founder and CEO of the Ananta Aspen Centre in New Delhi.

Later on Saturday, Rubio spoke with Ishaq Dar, Pakistan’s foreign minister. Dar told Geo News that Rubio urged him to de-escalate the situation because “both countries are nuclear states and the world would not support this.”

Hours later, around 3:30 p.m., Pakistan’s director general of military operations called his counterpart in India, said Indian Foreign Secretary Vikram Misri.

Ultimately, though, both sides agreed they would “stop all firing and military action” on land, air and sea from 5 p.m. onward.