* Unsmiling President Yanukovich signs deal with opponents
* Parliament changes constitution, sacks interior minister
* Criminal code amended to allow Tymoshenko release
* EU mediators says deal gives peace a chance
* Early presidential election this year
By Sabine Siebold and Natalia Zinets
KIEV, Feb 22 (Reuters) - A breakthrough peace deal for Ukraine halted two days of violence that had turned the centre of the capital into a war zone and killed 77 people, bringing sweeping political change that met many demands of the pro-European opposition.
Russian-backed President Viktor Yanukovich agreed to give up powers, hold early elections and form a government of national unity. Parliament voted for changes to the legal code that could see the release of Yanukovich's jailed rival, opposition leader Yulia Tymoshenko.
By nightfall, opposition leaders who signed the deal were addressing peaceful crowds from a stage in Independence Square, which for the previous 48 hours had been an inferno of blazing barricades and protesters were shot dead by police snipers.
Although the flames were out, the crowd was still defiant, holding aloft open coffins of slain demonstrators and making speeches denouncing the opposition leaders for shaking hands with Yanukovich.
The Ukraine crisis began with protests in November after Yanukovich turned his back on a far-reaching economic deal with the European Union in favor of closer ties with Russia instead.
If it holds, the deal hammered out with the mediation efforts of the foreign ministers of France, Germany and Poland, would mark a victory for Europe in a tug-of-war with Moscow for influence in the divided ex-Soviet state of 46 million people.
But it remains to be seen whether violence can be halted and whether a lurch away from Moscow will cost Ukraine a $15 billion Russian financial lifeline it needs to stave off bankruptcy.
"There are no steps that we should not take to restore peace in Ukraine," Yanukovich said in announcing his concessions before the agreement was signed. "I announce that I am initiating early elections."
Within hours, parliament voted to revert to a previous constitution slashing Yanukovich's powers, sacked his interior minister blamed for this week's bloodshed and paved the way for Tymoshenko's release.
EU leaders and the White House praised the deal but Moscow made grudging comments that fell short of endorsing it. The European foreign ministers signed the document as witnesses, but a Russian envoy did not.
The envoy, Vladimir Lukin, acknowledged Moscow had fallen behind the EU in diplomacy: "The EU representatives were in their own way trying to be useful, they started the talks.
"We joined the talks later, which wasn't very right. One should have agreed on the format of the talks right from the start," Lukin was quoted as saying by Interfax news agency.
Yanukovich, 63, a burly former Soviet regional transport official with two convictions for assault, did not smile during a signing ceremony at the presidential headquarters. Opposition leader Vitaly Klitschko, a retired world boxing champion, switched his nameplate to avoid sitting next to the president.
'YOU'LL ALL BE DEAD'
Polish Foreign Minister Radoslaw Sikorski described the agreement as a "good compromise for Ukraine". It "gives peace a chance. Opens the way for reform and to Europe," he tweeted.
It fell to Sikorski to sell the deal to the sceptical opposition. ITN video filmed outside a meeting room during a break in the talks showed him pleading with opposition delegates to accept it: "If you don't support this, you'll have martial law, you'll have the army, you'll all be dead."
Anti-government protesters remained encamped in Independence Square, known as the Maidan or "Euro-Maidan", and made clear their dissatisfaction at a deal that would leave Yanukovich in power until the early elections later this year.
Shortly after the signing ceremony, an open coffin carrying one of the dead from Thursday's violence was borne across the square as a bare-chested drummer beat out a funeral tattoo with people chanting "Heroes don't die! Bandits out!"
Some car horns hooted and fireworks were lit to celebrate the accord, but many activists were suspicious, noting that Yanukovich had cut deals before and was still in office.
When the three opposition politicians who signed the deal addressed the crowd in the evening, another coffin carrying a victim was carried through the crowd to the stage. After another open coffin was held aloft by the crowd, a protester wearing battle-fatigues leapt to the microphone.
"My comrade was shot and our leaders shake the hand of a murderer. It's a disgrace!" he said to roars of approval. "If it is not announced by 10:00 tomorrow that Yanukovich is gone, we're going to attack with weapons."
Earlier Klitschko drew cat-calls and derisive whistling from the crowd when he praised as "very important" their political achievements during the day. He later apologised for shaking Yanukovich's hand, telling the crowd: "If I offended anyone, I ask their forgiveness."
That was not enough for 35-year-old Volodymir from the western city of Lviv near the Polish border: "We won't follow Klitschko and the rest of them. They shook hands with a gangster and danced with the devil."
SET-BACK FOR PUTIN
The week's violence was by far the worst to hit Ukraine since it emerged from the breakup of the Soviet Union.
Ukraine, with borders drawn up by Bolshevik commissars, has faced an identity crisis since independence. It fuses territory that was mostly part of Russia since the Middle Ages with provinces that were parts of Poland and Austria until they were annexed by the Soviets in the 20th century.
In the country's east, most people speak Russian. In the west, most speak Ukrainian and many despise Moscow. Successive governments have sought closer ties with the European Union, but have been unable to wean their heavy Soviet-era industry from dependence on cheap Russian gas.
The past week saw the country on the verge of splitting, with central authority vanishing altogether in the west, where anti-Russian demonstrators seized government buildings and police fled. Deaths in the capital cost Yanukovich support of wealthy industrialists who previously backed him.
Many of those killed in the square were shot in the head and neck, apparently by snipers on rooftops. But Yanukovich proved unable to deploy enough loyal police to seize and hold the centre of the capital. Many police were among the dead.
If fully implemented, the deal would be a setback for Russian President Vladimir Putin, who had made tying Ukraine into a Moscow-led Eurasian Union a cornerstone of his efforts to reunite as much as possible of the former Soviet Union.
Moscow had maintained that the protesters were terrorists and coup plotters, had denounced the West for supporting them and encouraged Yanukovich to crush them.
"This is not democracy, this is anarchy and chaos. And we'll see what comes out of it," Alexei Pushkov, head of Russia's State Duma foreign affairs committee and a member of Putin's United Russia party said after the deal was signed, though he said the pact would be positive if it ended violence.
Washington took a back seat in the final phase of negotiations, its absence noteworthy after a senior U.S. official was recorded using an expletive to disparage EU diplomacy on an unsecured telephone line last month.
The outlook for Ukraine's economy is dire and Russia has not made clear whether it will still pay the promised $15 billion in aid. Ukraine cancelled a planned issue of 5-year Eurobonds worth $2 billion, it told the Irish Stock Exchange where the debt would have been listed. Kiev had hoped Russia would buy the bonds to help it stave off bankruptcy. (Additional reporting by Richard Balmforth, Alessandra Prentice, Vasily Fedosenko and Pavel Polityuk in Kiev, Sujata Rao in London, Alexei Anishuk in Moscow, Leigh Thomas in Paris, Marcin Goettig and Adrian Krajewski in Warsaw, Alexandra Hudson in Berlin; Writing by Peter Graff; Editing by Grant McCool)