Ukrainian rivals President Viktor Yushchenko and PM Viktor Yanukovych have agreed to hold early elections on 30 September, the president has said.
The two men appeared together to announce the deal
The announcement early on Sunday morning followed more than 12 hours of talks between the two men aimed at ending a long-running political crisis.
Mr Yushchenko said the crisis was now "finished" and a compromise reached.
In April, the president dissolved parliament, accusing his rival of trying to usurp his power.
The latest talks started after several hours' delay and went on into the early hours of Sunday morning before the two men signed a joint statement.
Key lawmakers, including opposition leader Yulia Tymoshenko, also attended.
"The political crisis in Ukraine is finished. We have come to a decision that represents a compromise," Mr Yushchenko announced.
"We remember everything, we will draw conclusions," Mr Yanukovych said.
"We will do everything so that this is not repeated, so that there are no more mistakes, no more emotions."
The BBC's Helen Fawkes in Kiev says many people will welcome the decision but will also realise that the root of the problem has not been dealt with.
Some may also see this as the president giving in to the prime minister, who had been insisting on an autumn election date, she says.
Fresh disagreements flared on Friday when Mr Yushchenko announced his intention to take control of 40,000 interior ministry troops.
His order came a day after riot police - acting on the orders of the interior minister - defended the offices of Ukraine's prosecutor-general, a Yanukovych ally who Mr Yushchenko had sacked.
Supporters from both sides have gathered in the capital, Kiev
He then ordered some 3,500 troops to head to Kiev but they were turned back by forces loyal to Mr Yanukovych.
Mr Yushchenko became president in January 2005 following the pro-democracy Orange Revolution, which overturned a rigged victory for Mr Yanukovych.
But Mr Yushchenko was forced to accept his rival as prime minister after his allies failed to win a majority in the March 2006 parliamentary election, and the two men have repeatedly clashed.
The president favours closer ties with the West, while the prime minister is seen as more pro-Russian.