Greek Prime Minister Alexis Tsipras survived a no-confidence motion in parliament on Saturday, setting the stage for the signing of a historic accord with neighboring Macedonia to settle a long dispute over the latter's name.
The motion brought by the opposition New Democracy party was rejected by 153 MPs, with 127 in favor. Political opponents had accused Tsipras of making too many concessions over the deal, due to be signed on Sunday.
Thousands of Greeks protested outside parliament against the accord with Macedonia, calling for Tsipras to resign. Police used stun grenades and tear gas to prevent them from entering the building.
"This is a deal I believe that every Greek prime minister would want," Tsipras told the chamber earlier.
Had he lost, the leftist elected in 2015 would have had to relinquish his mandate to the country's president, signalling early elections. He is already trailing centre-right New Democracy in opinion polls.
Greece had been in dispute with Macedonia since 1991 over the former Yugoslav republic's name, arguing it could imply territorial claims over the Greek province of Macedonia and an appropriation of ancient Greek culture and civilization.
The subject is a deeply emotional one for many Greeks. On Saturday, protesters outside the parliament building shouted "traitor, traitor!" as lawmakers debated inside.
"I'm just furious," said Theologos Ambotis, 69, a monk. "Conceding on the name is conceding on territory. Macedonia and Alexander the Great is Greek history and culture, and they are just giving it away to Skopje."
Under the terms of the accord, the country will be known as "Republic of North Macedonia" and Greece will lift its objections to the renamed nation joining the European Union and the NATO military alliance.
Greek foreign minister Nikos Kotzias and his Macedonian counterpart Nikola Dimitrov will sign the pact in the border lake region of Prespes on Sunday morning. Tsipras and Macedonian premier Zoran Zaev will also be present.
It will require ratification by both national parliaments and approval in a Macedonian referendum, which is not assured.
The president of Macedonia has said he will not endorse the pact, while in Greece, Tsipras's right-wing coalition partners have said their lawmakers will reject it when it is brought for ratification. That is expected to occur by the end of the year.
Protests were scheduled on both sides of the border on Sunday.
One lawmaker with the right-wing Independent Greeks, Tsipras's coalition partner, sided with New Democracy on the motion, bringing applause from opposition politicians. He was promptly expelled by the party's leader.
The expulsion brings Tsipras's majority in parliament to 153 MPs out of a total in the chamber of 300.
New Democracy leader Kyriakos Mitsotakis called the accord an affront, and the Tsipras government a 'nightmare'.
"This government should go before it does more damage, this time national damage," he said.