Pakistan's embattled government is preparing to call early elections in an attempt to find a way out of the political crisis that has paralysed the country, as a confidence vote in parliament and critical court cases loom on Monday.

At war with the courts, the opposition and the military establishment, President Asif Zardari's administration has agreed to an opposition demand to hold early national polls, but only after the separate election takes place in March for the Senate, the upper house of parliament, according to members of the ruling coalition and its advisers.

If the political parties cannot find a way out of the crisis, the threat of a coup remains, analysts warn.

Sectarian violence that has been simmering across the country erupted again with a bomb attack on Pakistan's Shia minority during a religious procession. Eighteen people were killed and more than 24 other injured in the blast in the central city of Khanpur.

"There is no other option for the government to come out of the current crisis without elections," said an adviser to the leadership of Zardari's ruling Pakistan Peoples party, adding that is was in its interests to reach an agreement with the opposition leader Nawaz Sharif.

The PPP rules with three other major coalition partners, but the alliance is looking shaky, with two of the parties, the Muttahida Quami Movement (MQM) and the Pakistan Muslim League-Q, distancing themselves from the government.

The government is willing to concede elections in the autumn, but Sharif is believed to be pushing for an even earlier date. In order to gain his help in continuing the government, Zardari may need to accept Sharif's demand.

A senior member of the coalition said it had so far agreed internally to a general election to be held in October. That would be just a few months before the February 2013 date when parliament would complete its five-year term and elections would have to take place anyway.

An early election should placate the courts and military. A supposedly neutral caretaker government would have to be installed to oversee a three-month election period.

Another coalition member said: "It is 100% certain that there will be elections in 2012. The only solution is elections. It doesn't matter whether they are held in June or October."

The resolution before parliament on Monday was tabled by the coalition itself, asking for support not for the prime minister, Yousuf Raza Gilani, or even the government, but for democracy. That makes it difficult for the opposition to vote against it.

But the PPP's troubles in parliament are only one of the fronts in its battle for survival. The courts and the military are both manoeuvring aggressively against the party's leaders, with two major cases coming up for hearing on Monday.

Both the so-called "memogate" scandal and a supreme court hearing against the legal amnesty that protects Zardari will be heard. In the amnesty case, the judges have threatened to disqualify the prime minister or president.

The testimony of the main witness in the memogate case, the US businessman Mansoor Ijaz, could lead to treason charges against key Zardari aide as well as the former ambassador to Washington Husain Haqqani. He is accused of trying to conspire with the US against Pakistan's armed forces in May last year by making a "treacherous" written offer to rein in Pakistan's military in return for US support for the civilian government, allegations that reach up to the president himself.

The row between the government and the army over memogate has become increasingly public and bitter. The military's spymaster has already told the court in a written affidavit that he believes Ijaz's allegations. Last week, Gilani and the chief of the army, General Ashfaq Kayani, traded rebukes over the military's court affidavits, with the former calling them "unconstitutional and illegal".

In a meeting with Zardari over the weekend, a furious Kayani reportedly demanded Gilani retract his remarks and apologise.

On Sunday Gilani came out fighting, making clear he would not bow to the military's demands.

"According to the constitution, the prime minister, the ministers, the ministers of state, are all answerable only to the parliament. I am not answerable to any individual," Gilani told reporters in the central city of Vehari.