* Ban Ki-moon calls Tunisia's new basic law a milestone
* Technocrat caretaker government to lead until new vote
* Tunisia's progress contrasts with Egypt, Libya
By Tarek Amara
TUNIS, Jan 27 Tunisia adopted a new constitution on Monday, a big stride towards democracy in the country that began the Arab Spring revolutions and has largely avoided the chaos and violence now plaguing the neighbours it inspired.
After years under autocrat Zine el-Abidine Ben Ali, Tunisia's charter has been praised as one of the most progressive in the Arab world, designating Islam as the state religion but protecting freedom of belief and sexual equality.
Parliament erupted in celebrations after the official signing of the constitution. Lawmakers approved it on Sunday evening, ending months of deadlock that had threatened to undo Tunisia's transition.
"This is an exceptional day for Tunisia, where we celebrate the victory over dictatorship. The government and the opposition have won, Tunisia has won," President Moncef Marzouki told the assembly after signing.
The small North African country's steady progress contrasts sharply with turmoil in Libya and Egypt, whose people followed Tunisia in ousting their veteran leaders in 2011.
Tunisia's stock market rose 1.7 percent on Monday in a sign of investor confidence in the country's stability, with the constitution in place and the formation of a new caretaker cabinet that will govern until elections.
After months of crisis, Tunisia's transition got back on track when ruling Islamist party Ennahda agreed to compromise late last year and step down to make way for a non-political cabinet of experts, led by former minister Mehdi Jomaa.
Hours before Sunday's approval of the constitution, new prime minister Jomaa named technocrats with international experience to key posts such as finance minister and foreign minister.
No election date has been set, but Ennahda and opposition party Nidaa Tounes, headed by a former Ben Ali official, are expected to battle for the presidency.
In the National Assembly and on the street, political divisions about the role of Islam were forgotten in the celebrations over a constitution that United Nations Secretary- General Ban Ki-moon commended as a "milestone".
"It is the first time we have been so united since the revolution," said Asma Habaib, a young bank worker in central Tunis. "It is like another revolution."
One of the most secular nations in the Arab world, Tunisia struggled after its 2011 revolution with divisions over the role of Islam and the rise of Islamist ultra-conservatives.
Islamist party Ennahda won the most seats in parliament, but the assassination of two opposition leaders last year pitched the country into crisis. Increasing deadlock in Tunisia, and the Egyptian army's deposing of its Islamist president in July, eventually prompted a compromise between Ennahda's chief Rached Ghannouchi and the opposition.
Divisions are still present, but Tunisia's leaders, heavily reliant on tourism for its foreign income, and with no tradition of violence or military interventions, opted to battle at the ballot box, not on the street.
Following that example will be tough for its North African neighbours.
Two years after its own NATO-backed revolt toppled autocratic leader Muammar Gaddafi, neighbouring Libya is caught in messy transition, with its constitution undrafted, its transitional parliament still deadlocked and former rebel fighters refusing to disarm.
In Egypt, elected Islamist President Mohamed Mursi was ousted by the army and jailed, and his Muslim Brotherhood movement declared a terrorist organisation.
Egyptians approved their own new constitution this month, but the country is still beset by political violence as army chief General Abdel Fattah al-Sisi pushes forward a transition plan that is expected to lead to him running for the presidency.
Tunisia's new premier Jomaa has plenty of challenges to secure stability before the elections in a country where many complain about the high cost of living and a lack of economic opportunities.
Islamist militants have been a growing threat in Tunisia, which shares a porous border with Libya, where al Qaeda-linked militants have sought refuge. A suicide bombing at a Tunisian beach resort late last year showed its vulnerability.
International lenders also want Tunisia to curb public spending on subsidies on fuel and basic goods to control the budget deficit. Protests broke out recently over a tax increase, forcing the government to roll back the measure.
"The adoption of a new constitution is an important step in reducing political uncertainty in Tunisia," Fitch Ratings agency said in a statement. "But easing political and social tensions will be a long and challenging process."