Prime Minister Benjamin Netanyahu said on Tuesday that an electronic fence along the Israel-Egypt border has saved the Jewish state from terrorist attacks or what he believes would be worse -- a tide of African migrants.

"Were it not for the fence, we would be faced with... severe attacks by Sinai terrorists, and something much worse, a flood of illegal migrants from Africa," Netanyahu's office quoted him as telling a development conference in the southern Israel desert town of Dimona.

The interior ministry says there are currently some 42,000 African migrants in Israel, mainly from Sudan and Eritrea, and the government has ordered that thousands of them must leave or face indefinite imprisonment.

They began slipping into Israel illegally in 2007 through what was then a porous border with Egypt's lawless Sinai region.

The frontier with Israel's Negev desert has since been given a 200-kilometer (124 miles) high-tech fence and the influx has halted.

Netanyahu said a tide of non-Jewish immigration would threaten the very fabric of Israel.

"We are talking about a Jewish and democratic state, but how could we assure a Jewish and democratic state with 50,000 and then 100,000 and 150,000 migrants a year," Netanyahu said.

"After a million, 1.5 million, we might as well shut up shop," he added. "We did not close down, we built a fence."

Today the mountainous Sinai is a battleground between the Egyptian army and Daesh terrorists.

The army launched a campaign on Feb. 9 after Egypt's Abdel Fattah al-Sisi, who is standing in elections this month for a second term, gave it a three-month deadline to crush Daesh in the Sinai.

Sisi issued his ultimatum in November after suspected Daesh gunmen killed more than 300 worshippers at a Sinai mosque associated with Sufi Muslim mystics.