Israel and Turkey agreed to restore full diplomatic relations on Friday after Prime Minister Benjamin Netanyahu apologized in a phone call for a deadly naval raid against a Gaza-bound international flotilla. The move was a dramatic turnaround partly brokered by President Barack Obama.

Joint interests between the two countries, including fears that the Syrian civil war could spill over their respective borders, and some cajoling by Obama, made the time ripe to repair the frayed relations after nearly three years of acrimony over the deaths.

It was a surprising turnaround for Prime Minister Benjamin Netanyahu who had long rejected calls to apologize. He announced the breakthrough after a 20-minute phone conversation with his Turkish counterpart, Recep Tayyip Erdogan. Obama helped broker the fence-mending while visiting Israel, but the sides had been reaching out to each other before.

“They agreed to restore normalization between Israel and Turkey, including the dispatch of ambassadors and the cancellation of legal steps against Israeli soldiers,” a statement from Netanyahu’s office said. Netanyahu “regretted the recent deterioration of relations between Israel and Turkey and expressed his commitment to overcoming their differences in order to advance peace and stability in the region.”

The statement stressed that the bloodshed was not intentional and suggested that relatives of those killed would get compensation. In light of an Israeli investigation into the shootings that pointed to a number of operational missteps, Netanyahu apologized to the Turkish people for “any mistakes that might have led to the loss of life or injury and agreed to conclude an agreement on compensation (and) non-liability,” the statement said.

It said Netanyahu appreciated Erdogan’s interview with a Danish paper in which he said he was misunderstood in remarks at a U.N. conference in Vienna. Erdogan said Islamophobia should be considered a crime against humanity “just like Zionism, like anti-Semitism and like fascism.” His comments drew wide condemnation. Erdogan later told Politiken that he was misunderstood and was criticizing Israeli policy.

Erdogan’s office said: “Our prime minister accepted the apology in the name of the Turkish people.”

Erdogan “expressed that it was saddening that relations, which are of vital strategic importance for peace and the stability of the region, have been soured in recent years,” the statement said.

Israel and Turkey were once close allies. Relations began to decline after Erdogan, whose party has roots in Turkey’s Islamist movement, became prime minister in 2003. Erdogan has embarked on a campaign to make Turkey a regional powerhouse in an attempt to become the leading voice in the Muslim world and distanced from Israel.

Tensions raged after Erdogan attacked Israel for the high Palestinian death toll in an Israeli campaign aimed at stopping daily rocket fire from Gaza on Israel in the winter of 2008, at one point storming off a stage he shared with the Israeli president at the high-profile World Economic Forum in Davos, Switzerland.

Relations gradually worsened.

A Turkish TV show that demonized Israeli soldiers prompted Israel’s then deputy foreign minister, Danny Ayalon, in early 2010 to reprimand the Turkish ambassador. He seated Ahmet Oguz Celikkol on a sofa lower than his own chair and wouldn’t shake his hand in televised images of the meeting.

Animosity peaked on May 31, 2010, when Israeli commandos stormed a ship named Mavi Marmara while stopping an international flotilla trying to breach an Israeli blockade of Gaza, which is ruled by Hamas, an Islamic militant group that has been branded a terrorist organization by Israel, the U.S. and the European Union.