Image copyright AFP Image caption General Raheel Sharif served as army chief from 2013-2016

The appointment of Pakistan's former army chief General Raheel Sharif to head a 39-country Saudi-led military alliance of Muslim countries to combat terrorism has set off intense debate in Pakistan and in the region.

The alliance is seen by many observers, but in particular by Shia Muslims in Pakistan and the Middle East, as a new Saudi-inspired Sunni block to counter Iran's growing influence among Shias in Syria, Iraq and Yemen.

After months of silence from Gen Sharif, Pakistan's defence ministry has now said that both Pakistan and Saudi Arabia have come to an agreement on his posting.

So far at least there does not seem to be an army made up of soldiers from any of these 39 countries and what exactly Gen Sharif will do in Saudi Arabia has not been disclosed.

But Pakistanis are anxious given that 20% of the population are Shia, there are large numbers of Shia officers and soldiers in the army - which has never faced sectarian unrest - and memories of the horrors of the 1980s when Saudi Arabia and Iran were accused of fighting a proxy war on Pakistani soil live on.

Each state, it was alleged, funded and supported militant Sunnis and Shia respectively in Pakistan to kill each other.

Image copyright AFP Image caption Pakistan's Shia have been targeted by militants, as in Parachinar on 31 March when a car bomb killed 24

Even today there are still widespread attacks launched largely by Sunni militants against Shia across Pakistan and the government has so far failed to bring this sectarian war to an end. Many Shia have left the country.

Unity hit?

The deal has prompted enormous debate in Pakistan, with the main opposition coming from Imran Khan's Tehreek-e-Insaf party, which says such a deal would worsen the Sunni-Shia rift in Pakistan.

The main advocate of the plan is Prime Minister Nawaz Sharif, who owes the Saudis several political debts, including his release from a jail sentence imposed a decade ago after he was toppled in a military coup. Mr Sharif then lived for many years in exile as a guest of the Saudis.

The army has also been historically close to the Saudis, providing troops and training in the 1980s to the Saudi armed forces and receiving help for the purchase of weapons systems.

Many Pakistanis are desperately keen that the country stay out of the crises that have gripped the Middle East.

Saudi Arabia and the United Arab Emirates are jointly trying to defeat the Houthi rebels in Yemen, who are Shia. The Saudis are also suspected of supporting a variety of militant Sunni groups fighting the regime of President Bashar al-Assad in Syria and of having helped Bahrain crack down on protests led by its majority Shia population.

Pakistan would like to avoid any involvement in these countries.

Image copyright AFP Image caption The Saudis are backing Yemen's exiled leader against the Houthi rebels

The Saudis have long asked Pakistan to contribute to its forces in Yemen, which so far Pakistan has refused to do. Last year Pakistan's parliament voted against sending Pakistani troops to Yemen. However the new Islamic alliance led by the Saudis and the appointment of Gen Sharif may alter the strategic picture for some.

Meanwhile Iran has increased its presence throughout the Middle East particularly in providing military aid to regimes in Iraq and Syria, while it is also allegedly helping the Houthis and other Shia in the region.

Iran has strongly objected to the appointment of Gen Sharif as head of the alliance. ''We are concerned that it may impact the unity of Islamic countries,'' said Iran's Ambassador to Pakistan Mehdi Honardoost on 4 April.

Islamabad insisted that it had told Iran of the appointment, but Tehran said that did not mean it had accepted the decision. Instead Iran has offered to help form a ''coalition of peace'' in the Middle East rather than forming a military alliance.

'Neutral referee'

Raheel Sharif's acceptance of the job has led to intense debate on political talk shows on TV channels, with many people questioning why a very popular former army chief should now enter the quagmire of the Middle East, which may ultimately force Pakistan to make difficult strategic choices and almost certainly sour its relationship with Iran.

Much of the print media has been critical of the appointment, which has not been helped by the total blackout of information from both the government and the army as to what exactly this alliance hopes to achieve or how it will benefit Pakistan.

''The government is pursuing a course of action that undermines Pakistan's status as a neutral referee in the Muslim world,'' said Pakistan Today in an editorial.

Newly appointed Foreign Secretary Tehmina Janjua has pledged that Pakistan will maintain a balance in its relations with Tehran and Riyadh "even though it's very challenging".

There has been longstanding criticism from politicians and the media that Pakistan has been ignoring Iran, even though it is an important neighbour. So far Gen Sharif's appointment has only increased that criticism and created considerable unease as to the future course of Pakistan's foreign policy.

Ahmed Rashid