"I am convinced that the referendum on the new name will be successful and that most citizens will say yes", said the Macedonian PM.
Athens, which like all members of both organisations has a veto over admissions, objected to its neighbour's use of the name Macedonia, arguing that it, along with articles in the constitution, could imply territorial claims over its own northern region of the same name.
In 2016, amid Europe's worst migrant crisis since World War II, Athens accused Skopje of using "excessive force" to push back hundreds of migrants trying to cross into Macedonia to continue their journey to northern Europe.
The prime ministers Alexis Tsipras and Zoran Zaev have agreed to refer to Macedonia as the Republic of Northern Macedonia or Severna Makedonija, as it is written in the Macedonian language.
Soon after his election in June 2017, Macedonian Prime Minister Zoran Zaev promised a new push to settle the name dispute and relaunched the drive for European Union and North Atlantic Treaty Organisation membership.
"This historic agreement is testament to many years of patient diplomacy, and to the willingness of these two leaders to solve a dispute which has affected the region for too long", Stoltenberg said.
Matthew Nimetz said in a statement he had "no doubt this agreement will lead to a period of enhanced relations between the two neighbouring countries and especially between their people".
By solving the dispute which has lingered for more than 25 years, Macedonia will remove the biggest obstacle on its path towards European Union and North Atlantic Treaty Organisation accession.
The deal still needs to be approved by the Macedonian and Greek parliaments.
European Council President Donald Tusk congratulated both sides.
"We are proud that this historic agreement was reached while two progressive governments are running both of the countries", PES president Sergei Stanishev said.
"Our bid in the compromise is a defined and precise name, the name that is honorable and geographically precise - Republic of Northern Macedonia".
"Today is a hard day for the Republic of Macedonia".
Officials in Albania are hailing the agreement between bordering Greece and Macedonia to end their decades-long name dispute as good for the whole Western Balkans region.
"I am keeping my fingers crossed", he said.
In a televised address, Mr Tsipras said the 140 countries which had recognised the Balkan state simply as Macedonia would now recognise it as Republic of North Macedonia.
He added that Macedonia "cannot and will not be able in the future to claim any connection with the ancient Greek civilisation of Macedonia".
But nationalist forces could try to upset the apple cart in Macedonia, with the opposition VMRO-DPMNE party in Skopje rushing to denounce the deal.