AFTER TWO decades of teetering between East and West, Ukraine may have reached a turning point. During the next two weeks, the country’s leaders must decide whether to go forward with a free-trade and political-association agreement with the European Union — a pact that would set the nation of 50 million on a course toward full integration with the West. A failure to do so could propel Ukraine into the arms of Russia, which is seeking to recruit it for a rival project — a Moscow-led Eurasian Union. The choice matters not only to Ukraine: Russian leader Vladi­mir Putin’s dream of recreating something like the old Soviet Union hinges on it, as does the post-Cold War vision of Western leaders of a Europe “whole and free.”

Ukraine’s elected president, Viktor Yanu­kovych, has made completion of the E.U. deal a key objective, and its parliament has passed crucial legislation to meet E.U. conditions. But one major hangup remains: the imprisonment of former prime minister Yulia Tymoshenko, a rival of Mr. Yanukovych who was convicted on dubious charges in 2011. European governments have warned that if Ms. Tymoshenko is not released, the planned signing of the pact at a regional summit meeting at the end of this month would not go forward. That would be a devastating setback for Ukraine’s hopes of modernizing its economy with Western trade and investment and consolidating its shaky democratic political system.

E.U. envoys have brokered a compromise plan, for the opposition leader to be allowed to travel to Germany for medical treatment. But it’s not clear that the plan will work. Ukraine’s parliament has been debating the proposal, and Russia’s allies — including many members of Mr. Yanukovych’s Party of Regions — are pressing hard to poison or kill the necessary legislation. Moscow is lobbying in its characteristically heavy-handed way, threatening Ukraine with a trade war or a cutoff of energy supplies if the E.U. pact goes forward. Mr. Yanu­kovych, a former client of Mr. Putin, himself appears to be wavering: He has promised to sign the legislation but has resisted issuing a pardon or executive order that would obviate the need for a parliamentary vote.

To their credit, E.U. leaders, especially from former Soviet-bloc states such as Poland and Lithuania, have been doing their best to persuade Mr. Yanukovych and the parliament to give up Ms. Tymoshenko and the Russian-style autocratic practices that her imprisonment represents. The Obama administration has been quietly lobbying as well. If the deal goes through, Ukraine will need plenty of backup from Brussels and Washington: In addition to possible Russian retaliation, the country is at risk of default on its foreign debt in the coming months and urgently needs financing from the International Monetary Fund or the private market.

It would be well worth the West’s effort to rescue Ukraine’s economy. First, however, Mr. Yanukovych and his party must make the right decision.