It seemed like a last-ditch public plea.

President Trump’s 8 p.m. deadline for Iran was fast approaching, and Pakistan was trying to orchestrate an off-ramp for both sides. So Prime Minister Shehbaz Sharif took to social media.

Mr. Sharif, adopting Trumpian parlance, said in a post on X Tuesday afternoon that diplomacy was “progressing steadily, strongly and powerfully” and that he was requesting that Mr. Trump extend the deadline for two weeks. He then tagged Mr. Trump and other top advisers.

But behind the scenes, the White House had already seen and signed off on the statement before Mr. Sharif posted it, according to a person briefed on the communication, a sign that the diplomatic channels were much more active than the message on social media suggested.

And it showed that the White House — even as Mr. Trump was threatening to wipe out Iran’s civilization unless Tehran agreed to reopen the Strait of Hormuz — was actively looking for a way out of the crisis as the deadline drew near on Tuesday.

A White House official denied that Mr. Trump wrote the statement, as some observers speculated on social media when Mr. Sharif initially posted the statement with the header: “*Draft – Pakistan’s PM Message on X*”. The Pakistani Embassy did not immediately respond to a request for comment.

The pitch worked, at least in the short term. Mr. Trump announced a few hours later that he was agreeing to a two-week cease-fire with Iran.