ATHENS — Macedonia agreed to change its name to resolve a decades-old dispute with Greece, the two countries said on Tuesday, and Greece said it would drop its objection to the neighboring country’s entry into the European Union and NATO if the changes are formally adopted.

Greece’s prime minister, Alexis Tsipras, said the country’s new name will be Severna Makedonija or Republic of North Macedonia. Greece had long opposed the name “Macedonia,” saying it implied territorial aspirations over a northern Greek region of the same name.

“I am deeply convinced that the agreement is a diplomatic success and a historic opportunity,” Mr. Tsipras said. He called it a “historic moment for the Balkans and our nations” and said it “opens a window to solidarity, friendship, cooperation, prosperity and mutual growth.”

Greece, which has blocked Macedonia from joining NATO and the European Union, said the deal will pave the neighboring country’s way into the two alliances as long as it follows through and formally adopts the name change.