TEL AVIV—Israel’s Prime Minister Benjamin Netanyahu on Saturday praised plans by U.S. President Donald Trump’s new administration to build a wall on the Mexico border, saying his country’s own barrier on the Egyptian border had halted illegal immigration.

“I built a wall along Israel’s southern border. It stopped all illegal immigration,” Mr. Netanyahu wrote on his official Twitter account, adding emoticons of the U.S. and Israeli flags. “Great success. Great idea.”

Earlier this week, Mr. Trump ordered his government to start on building a wall on the border with Mexico, as he attempts to crack down on immigration. He has also imposed a ban on entry to the U.S. for people from certain Muslim-majority countries.

Calls by the U.S. leader for Mexico to pay for the wall sparked a rift earlier this week with Mexican President Enrique Peña Nieto, who canceled a planned trip to Washington.

Mr. Netanyahu’s tweet drew criticism from the Mexican government and from Mexico’s Jewish community.