Ayatollah Ali Khamenei, Iran’s supreme leader, has called for Muslim unity many times in recent months. He told Iranian hajj officials last week that the “ummah shouldn’t practice hostility toward each other, but should support each other over important global issues.”However genuine this hope, there is growing concern in Tehran, reflected in parliament and in the media, over Sunni militancy. The nightmare is encirclement, with Baluchi unrest in eastern Iran growing just as ISIS gains strength to the west in Iraq and Syria.

Last week, Ebrahim Rahimpour, Iran’s deputy foreign minister for Asia and Pacific Affairs, headed to Pakistan. His visit was intended to carry forward the two countries’ agreement of last year to cooperate against crime and security threats.

But the trip was hastily arranged and followed clashes along the 900 km Iran-Pakistan border that lower-level contacts had failed to stop. The facts are far from clear, but it appears Iranian and Pakistani forces exchanged mortar fire on Oct. 25-26, a week after Iranian forces crossed the border and, according to the Pakistanis, killed one and wounded three border guards.

]Iran has alleged for some time that Pakistani security has failed to combat Baluchi militants using Pakistan as a base for operations in Iran. A few days before Iran’s cross-border action, militants killed at least four Iranian soldiers or border guards and, according to Akbar Naseri, an Iranian parliamentary deputy quoted by the Mehr news agency, Tehran warned it would act if Pakistan did not.

While no one is suggesting that Iran and Pakistan are about to go to war, clashes between the two countries’ armed forces are a dangerous development, especially as ISIS stirs popular tensions between Sunni and Shiites.

The root of the problem lies in the challenges both states face in managing the Baluchis, an ethnic group numbering over 10 million who straddle Iran’s Sistan-Baluchistan and Pakistan’s Baluchistan, poor provinces with widespread drug smuggling.

But matters take on a different dimension for mainly Shiite Iran since the Baluchis are, alongside the Kurds, one of the country’s two main Sunni minorities. Iran’s Sunnis allege discrimination in government employment and investment, and begrudge the absence of a Sunni mosque in Tehran and the common naming of buildings and streets in Sunni provinces after Shiite leaders.

Militant Baluchi groups, mixing separatist rhetoric with Al-Qaeda practices including beheadings, have carried out a low-level insurgency for some time. Last year Tehran last year executed 16 members of Jundallah, the most active faction, and declared their rebellion over. But a new group, Jaish al-Adl, began attacking Iranian security forces, kidnapping five border guards in February, of whom four were released after negotiations through Abdul-Hamid Esmaeel-Zehi, the main Sunni religious leader in the province.

Iran suspected the kidnapped guards were held inside Pakistan. As usual, the Pakistanis denied their side of the border was being used as a base and have continued these denials in the latest upsurge in violence. One official even suggested violence within Iran resulted from Baluchi resentment against religious discrimination.

This is certainly no time for the Pakistani authorities to be seen as ‘soft’ on Shiite Iran. Pakistan is wary of ISIS influence after several Pakistani Taliban commanders have declared their loyalty to Abu Bakr al-Baghdadi, leader of ISIS, and in the latest example of sectarian violence, eight Shiites were taken from a bus and gunned down in Quetta on Oct. 23 in Pakistani Baluchistan.

But any Pakistani equivocation, real or imagined, fuels the arguments of those in Tehran who want a strong stand and who dismiss President Hassan Rouhani’s promises to address the grievances of ethnic and religious minorities.

Whatever the political arguments in Tehran, Iranian security favors ‘strategic depth,’ whereby border provinces are heavily militarized to create a buffer. Such an approach can fuel resentment as much as improve short-term security.

In broader geopolitical terms, Iran has been adept in maintaining relations with both India and Pakistan, who themselves have recently clashed in disputed Kashmir with some 17 people killed since September.

Struggling to develop its substantial gas reserves in the face of U.S. sanctions, Tehran has long seen both Pakistan and India as lucrative potential markets. Even though India in 2009 pulled out of Iran’s ‘peace pipeline’ to supply gas to the sub-continent, it remains an important buyer of Iranian oil and is investing in Iran’s Chababar port, in Sistan-Baluchistan, partly to facilitate its trade with Afghanistan. And while Pakistan has put its leg of the pipeline on hold since 2012 due to U.S. pressure, it may reconsider this in the face of chronic domestic energy shortages.

But geopolitics and energy planning are more predictable and manageable than Shiite-Sunni rivalries. The Iranian public has been alarmed by the proximity of ISIS fighters, who are within striking distance of the border, especially in Iraq’s Diyala province. The need to soothe Iranians’ anxiety presumably explains October’s media pictures of Qassem Soleimani, the usually discrete commander of the Al-Quds special operations force, helping organize Kurdish resistance in Iraq against ISIS.

While ISIS has limited appeal for Kurds, given their Sufism and nationalism, even this may be cold comfort for Tehran. If ISIS continues to stir Kurdish separatism in Iraq and Syria, this could well encourage similar aspirations among Iran’s own restive 7-8 million Kurds. All in all, Ayatollah Khamenei’s Muslim unity looks a distant prospect.

Gareth Smyth has reported from the Middle East since 1992, and was the chief Iran correspondent of The Financial Times in 2003-07. He wrote this commentary for THE DAILY STAR.