Pakistan has launched missile strikes into Iran, reportedly killing nine people, after Iran carried out strikes in Pakistan late on Tuesday.
Pakistan said its strikes had hit "terrorist hideouts" in Iran's south-eastern Sistan-Baluchestan province.
Three women, two men and four children were killed, Iran state TV said.
The reciprocal air strikes come as tensions in the Middle East are high with several overlapping crises.
Israel is fighting the Palestinian group Hamas in Gaza and exchanging fire with Iran-backed Hezbollah in Lebanon, Iran-backed groups in Iraq and Syria are targeting US forces, and the US and UK have struck the Iran-backed Houthis in Yemen, who have been attacking shipping.
Pakistan and Iran have long accused each other of harbouring militant groups that carry out attacks from regions along their shared border.
On Thursday, Pakistan's foreign ministry confirmed its strikes, which Iranian media said took place around the city of Saravan.
Pakistan said it had acted in light of "credible intelligence of impending large-scale terrorist activities" and said a number of "terrorists" were killed.
It added that it "fully respects" Iran's "sovereignty and territorial integrity" but its action on Thursday was "a manifestation of Pakistan's unflinching resolve to protect and defend its national security against all threats".
Pakistan had fiercely condemned Iran's strike on Tuesday, which struck an area of Pakistan's Balochistan province near the Iranian border and which Islamabad said killed two children.
Iran insisted its strikes were aimed only at Jaish al-Adl, an ethnic Baloch Sunni Muslim group that has carried out attacks inside Iran, and not Pakistan's citizens.
Earlier in the week Iran also attacked targets in Iraq and Syria - it said it had hit Islamic State and Israel's Mossad spy agency, both of which it said had been involved in a bomb attack in the Iranian city of Kerman earlier this month which killed 84 people.
Analysts said Pakistan's response was not surprising and matched Iran's in being presented as a specific attack on insurgents.
"Pakistan's retaliation does raise the risk of escalation but it also provides an opportunity to step back from the brink. In effect, the two sides are even now," said Michael Kugelman, the South Asia director at the Wilson Center.
"Islamabad had a strong incentive to try to restore deterrence, especially with Iran on the offensive around the wider region deploying direct strikes and proxies to hit out at threats and rivals. In effect, if Pakistan had held back, it would have faced the risk of additional strikes."
Others suggested that the government in Islamabad was under domestic pressure to respond. The country, which saw its former leader Imran Khan removed nearly two years ago, is holding an election next month.
"There was a lot of public pressure on the government to do something and so they have done this just to prove that they are not less than [Iran], this act of sabre-rattling," said retired Lt General Asif Yaseen, a former Pakistani defence secretary.
But he said he had a "gut feeling that this will stop here for both the countries" and Pakistan could now be in a position to restart dialogue with Iran.
Some commentators have suggested Iran's strikes on Iraq, Syria and Pakistan this week were also driven by the current turbulent dynamics in the Middle East.
Tehran has said it does not want to get involved in the wider Israel-Gaza conflict but groups that it backs have been targeting Israel and its allies to show solidarity with the Palestinians.
However Shashank Joshi, defence editor at The Economist, says he does not believe the strikes are an outcome of the 7 October Hamas attacks on Israel, which killed about 1,300 people and triggered Israeli retaliation against Hamas in Gaza, which officials from the Hamas-run health ministry there say has killed about 24,000 people.
"The story here is about Iran flexing its muscles, perhaps outraged by what it saw as a grievous assault on its country [in Kerman on 3 Jan, which is] the worst terrorist attack in Iran since the revolution of 1979 ... Iran is wounded and is lashing out. I don't think there's any compelling reason to say the bombing was caused by, or is an outcome of 7 October," Mr Joshi told the BBC's Today programme.
He adds that this is "not the first time there have been border tensions, but it is by far and away the most serious escalation in tensions that I can remember".
China, a strong ally of both nations, has called for both sides to show restraint and avoid an escalation.