Macedonia will rename itself “North Macedonia” as part of a landmark agreement with Greece aimed at ending a 27-year-old dispute between the two countries.

Under the deal signed Sunday, Greece has pledged not to use a veto that has kept the Balkan country out of the North Atlantic Treaty Organization and the European Union.

The accord was...