When Iran and Pakistan traded airstrikes this week, both targeting what they said were militant camps, the exchange raised fears that the upheaval sweeping the Middle East was moving into new territory.

To Pakistan, which was hit first, it was important to send a clear message that violations of its sovereignty would not be tolerated. But the Pakistani military quickly followed its retaliatory action with another message — one that showed its desire to contain the tensions, a wish driven in no small part by the immense strain the country was under even before the Iran clash.

Pakistan signaled that it was seeking de-escalation by calling the two nations “brotherly countries” and urging dialogue and cooperation, language that Iran echoed in a statement of its own on Friday. Pakistan’s appeal, analysts said, underlined a plain fact: It could hardly be in a worse position to fight a war.

For two years, the country has been embroiled in an economic crisis and political turmoil that has directly challenged the country’s all-powerful military establishment. Terrorist attacks have resurged across the country. And already at odds with its archrival India, it has seen a souring of its once-friendly relations with the Taliban government in neighboring Afghanistan.

“At a moment when Pakistan is experiencing some of its most serious internal turmoil in years if not decades, the last thing it can afford is more escalations and a heightened risk of conflict with Iran,” said Michael Kugelman, the director of the Wilson Center’s South Asia Institute. “For Pakistan to be locked in serious tensions with not one or two but three neighbors — it’s a geopolitical worst-case scenario, bar none.”