Caught between the opposing views of President Trump and Democratic leaders, Israeli Prime Minister Benjamin Netanyahu reversed himself on Thursday and decided to prohibit two Democratic congresswomen from visiting Israel.

The move to bar Reps. Ilhan Omar (D-Minn.) and Rashida Tlaib (D-Mich.) followed an unusual intervention by Trump, who advisers say is trying to sow divisions within the Democratic Party by shining a spotlight on its most liberal members.

Hours before the decision to block the lawmakers, Trump tweeted that approving the visit would “show great weakness.” He also said that Omar and Tlaib “hate Israel & all Jewish people, & there is nothing that can be said or done to change their minds.”

Israel’s decision immediately opened up a new battle between Netanyahu and Democrats, who had privately warned Israeli Ambassador Ron Dermer that such a decision would be unprecedented and inconsistent with Israel’s claims of tolerance and openness.

But it also united the party’s leaders behind a simple message: Barring the travel of U.S. lawmakers for practicing free speech is unacceptable, and both Trump and Netanyahu are at fault.

House Speaker Nancy Pelosi (D-Calif.) called the move “deeply disappointing,” and House Majority Leader Steny H. Hoyer (D-Md.), who lobbied Israeli officials on Wednesday to allow the lawmakers to make a trip, called it “outrageous.”

Tlaib and Omar have said their criticisms of the Israeli government are based on policy differences and have repeatedly denied harboring any animus toward Jews or Israelis. Both have voiced their support for a boycott movement against Israel to oppose the treatment of Palestinians.

In a statement, Omar said the Israeli decision was not a surprise coming from Netanyahu, “who has consistently resisted peace efforts, restricted the freedom of movement of Palestinians, limited public knowledge of the brutal realities of the occupation and aligned himself with Islamophobes like Donald Trump.”

A senior White House official said that Trump never directly told Netanyahu to prohibit the visit but that advisers conveyed the president’s views to the Israeli government after it initially said the women would be allowed in.

Netanyahu “was certainly aware of the president’s position,” the official said. Like others, the official spoke on the condition of anonymity to discuss sensitive deliberations.

When asked whether he spoke directly to Netanyahu, Trump told reporters on Thursday, “I don’t want to comment about who I spoke to . . . but I did speak to people over there, yeah.”

The president’s advisers have given him mixed views on how to deal with four liberal congresswomen known as “the Squad,” which in addition to Omar and Tlaib includes Reps. Ayanna Pressley (D-Mass.) and Alexandria Ocasio-Cortez (D-N.Y.).

Some Trump aides have told the president to particularly focus on Omar and Tlaib because they are the most polarizing — and poll the worst — in the eyes of his campaign advisers.

Other U.S. officials worried that Trump’s opposition to their travel would backfire, one official said. Trump dismissed that advice, saying that Omar and Tlaib’s criticisms of Israel make them worthy targets.

But even some Republican critics of the congresswomen broke with Trump and Netanyahu.

“Denying them entry into #Israel is a mistake,” tweeted Sen. Marco Rubio (R-Fla.). “Being blocked is what they really hoped for all along in order to bolster their attacks against the Jewish state.”

The American Israel Public Affairs Committee, a powerful pro-Israel lobbying organization that rarely criticizes the Israeli government, said the congresswomen should be allowed to visit.

AIPAC said in a tweet that it disagreed with Omar and Tlaib’s support for the Boycott, Divestment and Sanctions movement, better known as BDS, which calls for boycotting Israeli goods and services to protest Israeli treatment of Palestinians. But the group added, “We also believe every member of Congress should be able to visit and experience our democratic ally Israel firsthand.”

The Democratic Party’s leading liberal presidential primary candidates swiftly condemned the decision, with Sen. Bernie Sanders (I-Vt.) calling it a “sign of enormous disrespect to these elected leaders” and Sen. Elizabeth Warren (D-Mass.) warning that it would be a “shameful, unprecedented move.”

Netanyahu insisted that his government continues to respect the U.S. Congress but said there are limits to whom it will allow entry. “As a vibrant and free democracy, Israel is open to all its critics and criticism, with one exception: Israeli law prohibits the entry of people who call and operate to boycott Israel,” he said in a statement.

Senior Democrats in Congress said they felt particularly misled by Dermer, Israel’s ambassador, who said last month that the two congresswomen would be allowed to visit Israel “out of respect for the U.S. Congress and the great alliance between Israel and America.” On Wednesday, Israeli officials notified Democrats that Netanyahu had changed his mind, sparking a last-minute lobbying campaign by Democrats to reverse the decision.

Several Jewish Democrats who have long been critical of Tlaib and Omar’s positions on Israel pleaded with Dermer on their colleagues’ behalf. Reps. Nita M. Lowey (D-N.Y.), Bradley Schneider (D-Ill.), Josh Gottheimer (D-N.J.) and Eliot L. Engel (D-N.Y.) — all strong supporters of Israel — phoned the envoy to lobby against barring the congresswomen. Hoyer took the lead on negotiating for the Democrats, but a Wednesday phone call with Netanyahu proved unsuccessful.

While some Democrats said privately that the move exposed Israel’s hard-right drift, Jewish House Democrats in particular worried that it will empower critics of Israel, fueling the BDS movement. In phone calls with lawmakers, Dermer tried to justify the decision, saying Omar and Tlaib had no real intention of visiting Israel or meeting with Israeli officials. He also criticized the group sponsoring the trip as radical.

Hoyer rejected that view in his statement, saying the decision is “outrageous, regardless of their itinerary or their views.”

An aide to Omar pushed back on the Israeli government’s assertion that their itinerary did not include meetings with Israeli officials. The staffer said she and Tlaib had meetings lined up with Arab and Jewish members of Knesset as well as planned visits with current and former U.S. ambassadors to Israel, David M. Friedman and Daniel B. Shapiro.

The aide also noted that other lawmakers, including Rep. Mark Pocan (D-Wis.), had visited Israel through the same pro-Palestinian group in previous years, using the same itinerary, and that Israel did not object. Those visits did not include huddles with Israeli officials, the aide continued, arguing that Israel’s justification for barring a member of the House Foreign Affairs Committee from the country was hypocritical.

Omar and Tlaib’s trip to Jerusalem and the West Bank was planned by Miftah, a nonprofit organization headed by Palestinian lawmaker and longtime peace negotiator Hanan Ashrawi.

On Thursday, the group called Israel’s decision “an affront to the American people and their representatives.”

“MIFTAH worked hard to organize a well-rounded visit . . . in order to facilitate their engagement with Palestinian civil society and to provide them with an opportunity to see the reality of occupation for themselves,” the group said in a statement. “This is their right and duty as members of Congress, who oversee US policies and actions that affect Palestine, Israel, and countries worldwide.”

The question about their entry status arose because of a recently passed Israeli law that denies entry visas to foreign nationals who publicly back or call for any kind of boycott — economic, cultural or academic — against Israel or its West Bank settlements.

Israeli Interior Minister Aryeh Deri, publicly confirming the decision to ban the two lawmakers, said Thursday that the move was coordinated among Netanyahu, Foreign Minister Israel Katz and Minister of Strategic Affairs Gilad Erdan in accordance with the law preventing those who advocate a boycott from entering Israel.

“The State of Israel respects the U.S. Congress, as part of the close alliance, but it is inconceivable that anyone who wishes to harm the State of Israel will be allowed,” Deri said in a statement.

Deri made clear that if Tlaib’s request to visit included a humanitarian reason — such as a private meeting with her family — then he would consider it. Two people close to Tlaib said she may still try to visit her grandmother in the West Bank, which Israel may allow on the condition that she does not promote any boycotts against Israel during the trip.

Trump, who maintains a close relationship with Netanyahu, said last month the lawmakers should “go back” to the countries they came from, in remarks widely condemned as racist. Tlaib was born in Michigan, and Omar was born in Somalia but became a U.S. citizen when she was a teen.

Eglash reported from Jerusalem. Anne Gearan and Ashley Parker in Washington contributed to this report.