(adds context on decision) TUNIS, Jan 9 (Reuters) - Tunisia's Islamist Prime Minister Ali Larayedh will resign on Thursday, handing power to a caretaker administration in a deal forged with his opponents to put the country's transition to democracy back on track, the state news agency said.
Three years after an uprising against autocrat Zine el-Abidine Ben Ali, Tunisia is in the final stages of establishing a full democracy before elections that would be a rare bright spot in an unstable region.
"The prime minister ... has declared he will hand his resignation to the president on Thursday afternoon," said a statement from the president's office that was published by state news agency TAP.
One of the most secular countries in the Arab world, Tunisia has struggled with divisions over the role of Islam and the rise of hardline Islamist militants since the uprising in 2011 that inspired other revolts in the region.
The killings of two secular opposition leaders by gunmen last year galvanised Islamist party Ennahda's secular foes who took to the streets to demand its members resign from power, accusing them of being too lax with hardliners.
Ennahda late last year reached a compromise with main opposition Nidaa Tounes to hand over power once parties had finished writing the new constitution, set a date for elections and appointed an electoral council to oversee the vote.
Much of that agreement has been done: The national assembly is voting on the last clauses of the new charter this week and on Wednesday night the assembly appointed a nine-member electoral commission.
Tunisia's new government will have to tackle economic reforms to cut back its deficit while managing simmering popular discontent over the high living costs and lack of economic opportunities since the revolution.
Authorities say Islamist militants from the group Ansar al-Sharia, whose leader pays allegiance to al Qaeda, are also a growing threat for the small North African country, whose economy relies heavily on foreign tourism.
Islamist parties who rose to political power after the 2011 revolts in Egypt and Libya have fared less well than Ennahda, whose compromise with secular opponents will allow them to again take part in elections this year.
Egypt's democratically elected President Mohamed Morsi is on trial after the military ousted him, and Libya's Muslim Brotherhood-allied party is locked in political crisis with secular foes in their parliament.