TUNIS (Reuters) - Tunisia, birthplace of the Arab uprisings of 2011, is locked in a standoff between its Islamist-led government and secular opposition that could be decisive for the success of its experiment in democracy.
The small North African nation could still make this work, if its political class can rise above party rivalries to follow a road map to the rule of law laid out in 2011, analysts say.
Optimism has waxed and waned over the past week as the central figure of Tunisian politics, Islamist leader Rached Ghannouchi, offered to consider a deal for new elections that could produce an orderly transfer of power to the opposition.
The ensuing squabbling in his Ennahda party and in the opposition, which responded by demanding the Ennahda-led government's immediate resignation, dampened the initial hopes his offer had stirred. Then upbeat comments by main opposition leader Beji Caid Essebsi brightened prospects again.
"Tunisia risks a lot in this crisis but it is not going to collapse," said political analyst Jamel Arfoui. "It will continue its transition because Ghannouchi is trying to find solutions to avoid an Egyptian scenario."
A replay of the Egyptian army's bloody crushing of the once- dominant Muslim Brotherhood in Egypt is hardly on the cards in Tunisia, where army coups are unknown and politics has rough edges but not the life-and-death polarisation haunting Cairo.
Instead of taking an us-versus-them stand, the only independent force in Tunisia that can play a role anything like that of Egypt's army - the powerful UGTT trade union federation - has stepped in to mediate between Islamists and secularists.
Crucially, Ghannouchi has read opposition protests as a sign it is time to compromise, not cling to power at all costs as Egypt's deposed Islamist President Mohamed Mursi tried to do.
"Ghannouchi is definitely a democrat," said Geoffrey Howard, North Africa analyst for the Control Risks consultancy group in London. "He's also a very canny operator."
Tunisia's latest crisis erupted in late July when Salafi Islamist militants assassinated a secular politician, the second such killing this year.
Accusing Ennahda of incompetence and laxity towards Islamist radicals, opposition parties called huge rallies to demand it immediately make way for a caretaker cabinet to hold new polls.
The head of the assembly writing a new constitution, which was elected in October 2011 with a one-year deadline that it missed, then suspended its work because of the unrest.
This meant Tunisia, whose current government was only meant to run affairs during a one-year transition, had strayed from the road map calling for a new constitution and then a caretaker cabinet to oversee voting for a fully democratic parliament.
The Egyptian army's ousting of Mursi on July 3 had already dealt a body blow to Islamist hopes of reshaping Muslim nations on more religious lines after decades of secular one-man rule.
These pressures seem to have prompted Ghannouchi, who during exile in Britain concluded that democracies offer religions more freedom than autocracies, to seek a consensus on new elections.
The problem now is to weather the transition. Ennahda has alienated many Tunisians by stressing its Islamist agenda while failing to tackle the country's economic and security problems.
It also aroused suspicion by placing its lieutenants in key administrative posts around the nation of 11 million, drawing charges that it could not be trusted to organise fair elections.
Over the past two weeks, Ghannouchi has accepted UGTT mediation for the transition and held an unprecedented meeting with opposition leader Essebsi, previously shunned by Ennahda as a relic of Tunisia's old order, to start discussing its details.
In one oft-mentioned scenario, work on the constitution would resume immediately and be finished by October 23, after which all-party talks would agree on a neutral caretaker cabinet to take over from Ennahda and quickly hold new elections.
But there are rumblings in Ennahda, especially among those who spent years in prison under former President Zine al-Abidine Ben Ali and who oppose compromise with Essebsi's Nida Tounes party because it represents many officials who served under him.
The emerging consensus has also sidelined Ennahda's two secular coalition partners, especially the Congress for the Republic (CPR) party whose trademark project - a law to ban those former Ben Ali officials from politics - has fallen victim to Ghannouchi's rapprochement with the opposition.
The leftist Popular Front is wary of Essebsi's cooperation with Ghannouchi because it wants his Nida Tounes party as an ally against Ennahda in the coming elections. It has called for more protests to pressure the government to resign now.
Wrangling over the constitution has been long and hard, with four months alone spent debating whether to mention sharia law in a special article, but the latest draft is almost finished without the controversial religious elements Ennahda wanted.
"The constitution is almost ready," said Amna Guellali, Tunisia researcher for Human Rights Watch. "If they have a political agreement, the rest can be done quite quickly."
But pre-election politics, with Ennahda casting its time in power in the best light and its foes jockeying for advantage, could throw up new hurdles to completing the transition.
Howard, the risk analyst, said he expected a technocratic government to emerge eventually, but predicted serious unrest if elections were delayed beyond the first quarter of 2014.
"The greatest danger is popular discontent," he said.
Additional reporting by Tarek Amara; Editing by Alistair Lyon