Prime Minister Benjamin Netanyahu solved Israel’s African asylum-seeker crisis. Twice over. And yet it is now utterly unresolved — with negative consequences for the migrants themselves, for the veteran residents of south Tel Aviv where most of the Africans live, for Israel’s moral choices and its reputation, for the well-being of the Supreme Court, and even for the standing of Netanyahu himself, who has managed to snatch defeat in every aspect of the crisis from the jaws of his own victory.

The current farcical and abysmal situation cries out for the adoption of an arrangement that Netanyahu himself rightly and proudly endorsed, but then immediately rejected. This article represents something of a plea to the prime minister: Rethink that ill-judged rejection.

The first of Netanyahu’s two successes came when he oversaw a major upgrade of Israel’s border fence with Egypt. Israel is the only First World country reachable over land from Africa, and tens of thousands of would-be refugees, asylum-seekers, economic migrants and/or infiltrators (depending on who’s talking) were making the arduous trek — notably from Eritrea and Sudan — in Israel’s direction, as word spread that this country was accessible to them. When Netanyahu warned — and he has warned often — that Israel could have faced a seven-figure influx, the concern was credible. Israel’s population of a little less than 9 million has a Jewish/non-Jewish ratio of 75 percent to 25 percent; the entry of a million African asylum-seekers would have shifted that balance, and profoundly remade it over time. As of five years ago, however, Netanyahu’s upgraded border fence (which is also a far more robust defense against Islamic State-linked terrorism) halted the flow of illegal entrants.

Another positive consequence of improving the border fence and stopping the influx was that it neutralized “torture camps” in the Egyptian Sinai. Approximately 7,000 asylum-seekers who made it to Israel got here after being kidnapped, imprisoned and in many cases tortured by mostly Bedouin gangs, who released them only after extorting money from their relatives in Israel or their home countries. (Such camps now operate in Libya.)

Netanyahu’s second success came earlier this month, when he unveiled a remarkably sensible agreement, negotiated with the United Nations High Commissioner for Refugees (UNHCR), to share responsibility for the 30,000-40,000 asylum-seekers who made it in before the border was all but sealed. About half of them, he announced with considerable satisfaction at a press conference he convened at the Prime Minister’s Office on the afternoon of April 2, would be relocated to Western countries — he mentioned Canada, Germany and Italy, and some reports also cited the United States and Sweden — while Israel would grant temporary residency to the other half.

The bombshell (in a good way) agreement was manifestly a win-win.

Efforts to compel the asylum-seekers to leave had not been successful. Attempts to forcibly deport unmarried men to Uganda and Rwanda had been frozen by the Supreme Court, which was unpersuaded by the state’s insistence that they would come to no harm there. The Jewish state seeming to hardheartedly expel would-be refugees was deeply troubling to many Israelis, Diaspora Jews and other supporters of Israel, and was grist to the propaganda mill of Israel-haters worldwide. The fact that these were black Africans only added to the potential for Israel-bashing; we could be depicted as racist as well as heartless, and never mind the fact that Israel has rescued from civil war and worked to integrate tens of thousands of black Jews from Ethiopia.

As presented by Netanyahu, the deal also provided for an investment of resources to arrange for those asylum-seekers who were staying to obtain lawful work around the country, with vocational training. They would thus be an asset rather than an economic strain on the state, and they would no longer be overwhelmingly concentrated in south Tel Aviv. Meantime, those south Tel Aviv neighborhoods deeply impacted by their arrival — where some veteran residents had become the most vocal opponents of their presence — would be rehabilitated.

The arrangement was even financially advantageous to the Israeli taxpayer. The Population Authority, overseeing the asylum-seeker issue, had estimated that the total cost of deportation to one or more African countries would be around NIS 300 million (about $85 million), which would not include the kind of reported secret $5,000 per person payments made to the Rwandan government for deportees they accepted in the past. In the UNHCR arrangement, resettlement costs would be absorbed by the UN and the third country, with minimal cost to Israel.

No matter how emphatic the opposition in some quarters to the absorption of any African migrants here, there was, and there is, no prospect of Israel forcing them all out. Even before the UNHCR plan was announced, Israel had stated it would not deport asylum-seeker women, children, or married men

In summary, then, the migrants who were leaving would have a credible chance of a good life in the welcoming West. Those who were staying would get legal status. The neighborhoods that had taken the strain would revive. Taxpayers would benefit. The Supreme Court’s concerns would be alleviated. The international community would be doing its bit to solve the crisis, and Israel would be acting humanely to carry its share of the burden and responsibility.

No wonder Netanyahu, at his April 2 press conference, described the arrangement as “the best possible” deal.

Except that hours later, he froze it.

And the next day, he canceled it altogether.

The people he had described as “migrants” the night before were now “infiltrators,” and the idea of granting some of them temporary residency, vocational training, and the rights and opportunities to work, was off the table.

Why on God’s green Earth would the prime minister have scrapped an arrangement that could not credibly have been bettered? No matter how emphatic the opposition in some quarters to the absorption of any African migrants here, there was, and there is, no remote prospect of Israel forcing them all out. Even before the UNHCR plan was announced, Israel had stated it would not deport asylum-seeker women, children (who have known no other country but Israel), or married men. Shlomo Mor Yosef, director of the Population Authority, told The Times of Israel‘s Melanie Lidman in late March that only half of the asylum seekers could thus be deported, almost exactly the same proportion as the UNHCR plan was readying to resettle in third countries.

The way Netanyahu told it, he’d been prompted to reconsider, in large part, because of objections from the residents of south Tel Aviv. “I hear you, and especially the residents of south Tel Aviv,” he said in a (Hebrew) Facebook post when he froze the deal on the evening of April 2, just a few hours after he’d announced it. “Every year I make thousands of decisions benefiting the State of Israel and Israeli citizens. Occasionally a decision is reached that has to be reconsidered,” he elaborated soon after.

What went on in the short hours between delighted announcement and embarrassing volte-face did indeed include vocal objections from some local residents. But more significantly, Netanyahu came under public onslaught from hawkish political rivals, notably including Jewish Home leader Naftali Bennett, and a social media onslaught involving his own Likud voting base. In 2012, Miri Regev — then a plain old Likud MK, and today the minister of culture and a would-be prime minister — had called Sudanese asylum-seekers “a cancer in our body” in an address she delivered in south Tel Aviv. Regev subsequently apologized for the statement, and said it had been misconstrued. But it was a “cancer in our body”-style backlash that Netanyahu found himself facing on the evening of April 2, from his own supporters.

There can be no doubt that Netanyahu knew the angry objectors were in the wrong — even from their point of view. By far the most likely consequence of scrapping the deal was not that more migrants would be taken out of Israel, as the angry chorus demanded, but that far fewer of them would leave. (The longer this unhappy saga takes to play out, furthermore, the more migrants will build families here, and the fewer Israel will ever be able to deport.) And yet Netanyahu buckled — buckled in record time.

This week, the fiasco reached its predictable peak. After scrapping the good deal, Netanyahu tried in vain to revive a bad one. He sent an emissary to Uganda to try to persuade the authorities there to accept forcibly deported migrants. He attempted to find other African countries who might take them. He failed, and in the process embarrassed some of the very countries with which he has had such success in building relationships in recent years, undermining those ties.

Ultimately, inevitably, the state found itself with no choice but to inform the Supreme Court, in its latest hearing Monday, that all intended forced deportations of African migrants were hereby canceled. For the time being, at least, they’re all staying. At still further cost to Israel, it is now intending to reopen the Holot detention center, for those theoretically slated for deportation to who knows where.

The saga doesn’t end even there, however. Smelling blood, the emboldened hawks, led by Bennett, are now energetically taking up legislation to try to constrain the Supreme Court — those interfering justices who have the gall to overrule Knesset legislation they consider undemocratic and who suspended the government’s original plan — its pre-UN deal plan — for forced deportations. While his coalition rivals issue ultimatums, Netanyahu is twisting and turning, preferring not to go down in history as the man who destroyed Israel’s independent judiciary, while also relentlessly anxious to avoid alienating that precious voter base that keeps him in power.

And thus a win-win arrangement, rightly, enthusiastically but only briefly adopted by the prime minister, has turned into a lose-lose turning point for Israel. The migrants of south Tel Aviv are going nowhere. The Supreme Court is under legislative attack. And, irony of ironies, none of this is helping Netanyahu, whose political foes smell blood.

But it’s still not too late to do what was, and is, the right thing.

Melanie Lidman contributed reporting to this article.