"Our two countries should step out of the past and look to the future," said Macedonia Prime Minister Zoran Zaev.
"Our peoples want peace... we will be partners and allies," he said. The accord begins to unravel one of the world's longest -- and arguably most arcane -- diplomatic disputes, which began 27 years ago with Macedonia's declaration of independence but whose roots date back centuries.
"The time has come again to sing happy songs in the Balkans," Tsipras said, moments before the document was signed by the two countries' foreign ministers.
Zaev and several of his ministers arrived by speedboat at the picturesque fishing village of Psarades under a sunny sky, on the southern bank of Lake Prespa that is one of the natural boundaries between the two countries.
Tsipras and Zaev embraced on the village dock and entered the large tent where the deal was signed to a standing ovation from gathered dignataries and officials.
UN under-secretary-general for political affairs Rosemary DiCarlo, longterm UN negotiator Matthew Nimetz, EU diplomatic chief Federica Mogherini and EU enlargement commissioner Johannes Hahn were at hand.
Nimetz, who turned 79 on Sunday and also signed Sunday's agreement, had been trying to broker a solution since 1994, first as a US envoy and subsequently on behalf of the United Nations.
But it was the election of Zaev in 2017, replacing nationalist PM Nikola Gruevski, that proved crucial.
An economist and former mayor of Strumica, Zaev made rapprochement with Greece a priority to secure his country's membership of the European Union and NATO, blocked by Athens for years.
After the signature, Tsipras will cross over to the Macedonian side of Lake Prespa for lunch, becoming the first Greek prime minister to visit the neighbouring state.
Since 1991, Athens has objected to its neighbour being called Macedonia because it has its own northern province of the same name, which in ancient times was the cradle of Alexander the Great's empire -- a source of intense pride for modern-day Greeks.
The two premiers, born just months apart in 1974, have bucked strong hostile reactions at home to push ahead with the agreement.