Hungarian Prime Minister Viktor Orban and Vladimir Putin, who have built ties as the Russian president grew increasingly isolated from most European Union leaders, sealed a gas agreement in Budapest.

Hungary is “relieved” that it will be able to roll over the unused portion of its 20-year supply agreement with Russia, which ends this year and for which Hungary would have had to pay at expiry, Orban told reporters after meeting Putin Tuesday. OAO Gazprom may boost the amount of gas it stores in Hungary, Putin said, adding that Russia also supports having a new gas pipeline, which would circumvent Ukraine, link with Hungary.

“Every question was settled according to the way our Hungarian friends wanted it,” Putin said.

Orban has often cited Hungary’s dependence on Russian energy in opposing stiffer sanctions over the Ukraine crisis as he sought to balance duties as a leader of an EU country with bilateral ties. Orban held his second official meeting with Putin in a little more than a year, as the Russian leader’s meetings with the 28-nation bloc’s officials became less frequent since pro-European Ukrainians rose up in late 2013 and ousted their Kremlin-backed leader last February.

“Isolating Russia isn’t sensible,” Orban said, adding at the same time that Hungary “wouldn’t divide Europe.” Russia and the EU need to continue engagement in order to come to a peaceful solution for Ukraine, Orban said.

Hungary has backed EU sanctions against Russia for the Kremlin’s alleged support of separatists in Ukraine, even as Orban criticized them amid warming ties with Putin. Russia supplies at least 60 percent of Hungary’s gas consumption, according to the International Energy Agency.

Energy Deals

Last year, Orban agreed with Putin on a loan of about 10 billion euros ($11.4 billion) to expand Hungary’s nuclear power plant, and Russian state-owned gas exporter Gazprom agreed to store as much as 700 million cubic meters of gas in Hungary.

Gazprom is open to raising the amount of gas stored in Hungary, Putin said Tuesday. He said Russia also supports connecting a potential new pipeline running from Turkey through Greece and the Balkans to Hungary. Orban added that he reached a“political agreement” with Putin on the unused portion of the gas contract and that technical details would be ironed out later.

Orban, who as recently as 2008 urged Hungary to avoid becoming the “happiest barrack of Gazprom,” has struck a different tone with Russia since he returned to power in 2010, after serving as prime minister from 1998 to 2002.

South Stream

He supported South Stream, a Russian-backed pipeline that would have circumvented Ukraine, until Putin canceled the project last year, citing the EU’s opposition. The Hungarian leader also rankled some of his EU counterparts and the government in Kiev with a call for autonomy for ethnic Hungarians in Ukraine, echoing similar demands for the Russian minority by the Kremlin.

At home, Orban extolled what he labeled “illiberal democracy,” citing Putin’s Russia as one example. More than 1,000 people demonstrated on Monday in Budapest against Putin’s visit, calling for greater European and less Russian influence in Hungary, Index news website reported.

More recently, Orban has toned down his rhetoric as relations suffered with NATO allies, including the U.S. He pledged to follow Berlin’s cue on foreign policy and hosted Merkel this month. Orban also traveled to Kiev to meet President Petro Poroshenko after the cease-fire agreement in Minsk.

“Orban has gone from taking two steps east and one step west to taking two steps west and one step to the east,” Tamas Boros, a political analyst in Budapest, said Monday. “He’s trying to switch tack without losing his balance.”