KIEV, Ukraine—President Viktor Yanukovych agreed to a European-brokered compromise with his opponents Friday in a deal that pulled the country back from spiraling violence and requires the Russian-backed leader to share power with rivals who support closer ties to Europe.

The deal marks a dramatic reversal for Mr. Yanukovych, who diplomats and officials said had been planning to deploy troops against antigovernment protesters this past week, but ultimately agreed to call early presidential elections and to cede some power to parliament.

The agreement—if it holds—could spell the end of Mr. Yanukovych's political career. Within hours of the signing, parliament overwhelmingly passed legal changes that would lead to the release from jail of his political nemesis, former Prime Minister Yulia Tymoshenko.

The deal also looks like a major setback for Russia, which only three months ago seemed to have succeeded in drawing Kiev firmly into its orbit. Mr. Yanukovych, facing heavy Russian economic pressure, abruptly backed out of a deal with the European Union in favor of closer ties with Moscow, which offered a $15 billion lifeline.

Russian officials were publicly cautious about the agreement but the White House said that President Vladimir Putin, in a call with Barack Obama, agreed that the deal should be implemented quickly. Russia's Foreign Ministry said it was ready to work with Ukraine to help "normalize the situation."