* Riot police use teargas on protesters near Mursi's palace
* President leaves premises as a precaution
* Prime minister says "majority consensus" favours referendum
* Big stakes in future of biggest Arab country and U.S. ally
Egyptian police battled thousands of protesters outside President Mohamed Mursi's palace in Cairo on Tuesday, prompting the Islamist leader to leave the building, two presidential sources said.
Police fired teargas at demonstrators angered by Mursi's drive to hold a referendum on a new constitution on Dec. 15. Some broke through police lines around his palace and protested next to the perimeter wall.
Several thousand people had gathered nearby in what they dubbed "last warning" protests against Mursi, who infuriated opponents with a Nov. 22 decree that expanded his powers. "The people want the downfall of the regime," the crowd chanted.
"The president left the palace," a presidential source, who declined to be named, told Reuters. A security source at the presidency also said the president had left the building.
Mursi ignited a storm of unrest in his bid to prevent a judiciary still packed with appointees of ousted predecessor Hosni Mubarak from derailing a troubled political transition.
Riot police at the palace faced off against activists chanting "leave, leave" and holding Egyptian flags with "no to the constitution" written on them. Protesters had assembled near mosques in northern Cairo before marching towards the palace.
"Our marches are against tyranny and the void constitutional decree and we won't retract our position until our demands are met," said Hussein Abdel Ghany, a spokesman for an opposition coalition of liberal, leftist and other disparate factions.
Despite the latest protests, there has been only a limited response to opposition calls for a mass campaign of civil disobedience in the Arab world's most populous country and cultural hub, where many people yearn for a return to stability.
A few hundred protesters gathered earlier near Mursi's house in a suburb east of Cairo, chanting slogans against his decree and against the Muslim Brotherhood, from which the president emerged to win a free election in June. Police closed the road to stop them from coming any closer, a security official said.
Opposition groups have accused Mursi of making a dictatorial power grab to push through a constitution drafted by an assembly dominated by Islamists, with a referendum planned for Dec. 15.
Egypt's most widely read independent newspapers did not publish on Tuesday in protest at Mursi's "dictatorship". Banks closed early to let staff go home safely in case of trouble.
Abdelrahman Mansour in Cairo's Tahrir Square, the cradle of the anti-Mubarak revolt, said: "The presidency believes the opposition is too weak and toothless. Today is the day we show them the opposition is a force to be reckoned with."
After winning post-Mubarak elections and pushing the Egyptian military out of the political driving seat it held for decades, the Islamists sense their moment has come to shape the future of Egypt, a longtime U.S. ally whose 1979 peace treaty with Israel is a cornerstone of Washington's Middle East policy.
The Muslim Brotherhood and its allies, who staged a huge pro-Mursi demonstration on Saturday, are confident that enough members of the judiciary will be available to oversee the mid-December referendum, despite calls by some judges for a boycott.
Cairo stocks closed up 3.5 percent on Tuesday as investors took heart at what they saw as prospects for a return to stability in a country whose divisions have only widened since a mass uprising toppled Mubarak on Feb. 11, 2011.
Mohamed Radwan, at Pharos Securities brokerage, said the Supreme Judicial Council's agreement to supervise the referendum had generated confidence that the vote would happen "despite all the noise and demonstrations that might take place until then".
"NO WAY PERFECT"
Prime Minister Hisham Kandil, a technocrat with Islamist sympathies, said in an interview with CNN: "We certainly hope that things will quiet down after the referendum is completed."
He said the constitution was "in no way a perfect text" that everyone had agreed to, but that a "majority consensus" favoured moving forward with the referendum in 11 days' time.
The Muslim Brotherhood, now tasting power via the ballot box for the first time in eight decades of struggle, wants to safeguard its gains and appears ready to override street protests by what it regards as an unrepresentative minority.
It is also determined to stop the courts, which have already dissolved the Islamist-led elected lower house of parliament, from further obstructing their blueprint for change.
Mohamed ElBaradei, coordinator of an opposition National Salvation Front, has said Mursi must rescind his decree, drop plans for the referendum and agree on a new, more representative constituent assembly to draft a democratic constitution.
In an opinion piece published in the Financial Times, he accused Mursi and the Brotherhood of believing that "with a few strokes of a pen, they can slide (Egypt) back into a coma".
ElBaradei, a Nobel Peace Prize laureate who once headed the U.N. nuclear watchdog, wrote: "If they continue to try, they risk an eruption into violence and chaos that will destroy the fabric of Egyptian society."
Despite charges that they are anti-Islamist and politically motivated, judges say they are following legal codes in their rulings. Experts say some political changes rushed through in the past two years have been on shaky legal ground.
A Western diplomat said the Islamists were counting on a popular desire for restored normality and economic stability.
"All the messages from the Muslim Brotherhood are that a vote for the constitution is one for stability and a vote against is one for uncertainty," he said, adding that the cost of the strategy was a "breakdown in consensus politics".