Ukraine's president, Viktor Yanukovich, and three opposition leaders have signed an agreement intended to end a crisis that sparked bloody clashes between protesters and police on the streets of the capital, Kiev.

The deal sets out plans to hold early presidential elections, form a national unity government and revert to the 2004 constitution, removing some of the president's powers. Yanukovich did not smile during a signing ceremony lasting several minutes in the presidential headquarters, but he did shake hands with the opposition.

The deal was also signed by two European Union foreign ministers who helped broker it in tortuous negotiations that lasted more than 30 hours. "This agreement is not the end of the process. It's the beginning of the process," the German foreign minister, Frank-Walter Steinmeier, said after the signing.

He said it was not perfect but the best agreement that could have been reached. "With it Ukraine has got the chance to resume its way to Europe," he said.

Parliament subsequently began to vote to make the agreement law, supporting immediately a return to the constitution of 2004 and an unconditional amnesty for people detained in the unrest. It also voted to allow the release of the former prime minister Yulia Tymoshenko after more than two years in prison.

Legislators voted by 310-54 to decriminalise the count under which Tymoshenko was imprisoned, meaning she was no longer guilty of a criminal offence. "Free Yulia! Free Yulia!" legislators chanted after the vote. It was not immediately clear when she might be released from prison in the eastern city of Kharkiv where she is serving her sentence.

The diplomatic breakthrough was confirmed earlier in a tweet from the German foreign office. "After talks with FM Steinmeier, Maidan's civic council [the protest leadership] decided to mandate opposition leaders to sign agreement," it said.

Oleh Tyahnibok, an opposition leader, said the protest council had reached an agreement with the acting minister of interior to resolve the crisis, in which 100 people are thought to have been killed in the last three days.

An aerial view shows the anti-government protest camp in Independence Square. Photograph: Vasily Fedosenko/Reuters

Poland's foreign minister, Radek Sikorski, was caught on video telling a protest leader: "If you don't support this deal you will have martial law, the army. You'll be dead."

Herman Van Rompuy, president of the European council, welcomed the deal in more diplomatic terms, tweeting: "#Ukraine: welcome the agreement; necessary compromise, launch of indispensable political dialogue for democratic, peaceful way out of crisis."

The agreement, published in full on the German foreign ministry website, states that presidential elections should be held no later than December and that the authorities will not impose a state of emergency, on condition that the authorities and opposition refrain from further use of violence.

The sides also agreed that an investigation must be launched into the acts of violence committed during the unrest, under joint monitoring from the Ukrainian authorities, opposition and the Council of Europe.

In a statement published on the presidential website before the deal was signed, Yanukovych said: "There are no steps that we should not take to restore peace in Ukraine."

The Germans said the talks had been "very difficult", continuing all night and stopping for a break after 7am. It was not clear whether protesters would accept the deal. Anton Solovyov, 28, an IT worker in the central square, said: "This is just another piece of paper. We will not leave the barricades until Yanukovych steps down. That's all people want."

After the worst bloodshed in the country's 23 years of independence, Kiev awoke to a bright, sunny and peaceful day, with the city centre firmly in the hands of the anti-Yanukovych protest movement, and the riot police – ubiquitous until Thursday morning – barely to be seen. It was not long, however, before shots rang out through Independence Square as police clashed with protesters.

"Participants in the mass disorder opened fire on police officers and tried to burst through in the direction of the parliament building," a police statement said.

Thousands remained on Independence Square, or Maidan, after police pitched battles on Thursday. The protesters had vastly expanded the area of the city centre under their control and quickly built huge barricades and reinforced positions to keep the security forces at bay.