President Trump is frustrated with Israeli Prime Minister Benjamin Netanyahu. The question is whether he will ever be angry enough to do anything about it.

Trump has told several aides in recent weeks that Netanyahu prefers using military force to compel Hamas’s surrender, instead of the president’s preferred method of a negotiated cease-fire. His frustration boiled over last week hours after Israel attacked Hamas negotiators in Qatar , an operation that threatened to derail fragile peace talks.

“He’s f—ing me,” Trump said about Netanyahu, according to officials who heard the comment. Trump was in conversation with senior aides, including Secretary of State Marco Rubio , about how to respond to the brazen strikes.

Trump’s sometimes heated feelings about Netanyahu have puzzled Washington. Why is Trump, who prefers to keep the upper hand in relationships, willing to let Netanyahu continually operate in direct defiance of his wishes?

“It’s slightly baffling and counterintuitive,” said Shalom Lipner , who served seven consecutive Israeli prime ministers in their offices over a quarter-century and is now at the Atlantic Council, a Washington think tank.

“Netanyahu’s moves have prolonged the Gaza war, created trouble for Trump with other U.S. allies in the region and made the expansion of the Abraham Accords excruciatingly difficult,” said Lipner, referring to Israel’s normalization of relations with a handful of Arab countries.

Trump has on occasion used harsh language about Netanyahu, including after the Israeli leader congratulated Joe Biden on his presidential victory in 2020, when he told journalist Barak Ravid that he considered the Israeli leader disloyal: “F—him.”

But Trump’s criticism appears to have done little to dissuade Netanyahu or weaken him. “I’m mystified and so are many other Israelis,” said Itamar Rabinovich , a former Israeli ambassador to the U.S. during the Clinton administration. “He’s under siege and makes mistakes. The only thing that’s really working for him is Trump’s support.”

Trump’s exasperation hasn’t turned into any form of public pressure: He has refused to leverage America’s vast military and political support for Israel, as well as his warm personal rapport with Netanyahu. Rather, he has opted to stand by as Israel launches a massive offensive into Gaza City and watch the prospects of his desired peace deal slip away.

The White House declined to comment.

A senior Israeli official described the relationship between Netanyahu and Trump as excellent and that reporting to the contrary was “fake news.” U.S. and Israel interests and core values are closely aligned, the official added.

One reason is that Trump and Netanyahu are kindred spirits, people who know them say. Both believe they have faced persecution from their countries’ elites, including criminal trials, and both see themselves as outsiders reforming a corrupt system.

Omer Dostri , a former spokesperson for Netanyahu, described ties between the two as “very, very tight.”

Another reason for the continued warm relations is the Israeli leader’s influence with Congress and in Republican-centric media, according to people familiar with Netanyahu’s thinking. Netanyahu often meets with U.S. lawmakers in Israel, and his interviews with American media in recent months have largely been with outlets viewed by Trump supporters, including Fox News, Newsmax , and OAN.

While Democratic support for Israel has plummeted in recent years, it remains high among Republicans. A Gallup poll in July found two-thirds of Republicans have a favorable view of Netanyahu, in contrast to 9% of Democrats.

“Republicans want to see a success story against Hamas,” said Avner Golov , a former senior director at Israel’s National Security Council and now vice president of MIND Israel, a security-focused nonprofit based in Tel Aviv.

Some cracks in Israel’s strong support from Republicans have started to show. Members of Trump’s MAGA coalition have openly criticized Israel, and Netanyahu specifically, arguing the continued war in Gaza threatens to draw the U.S. deeper into the conflict. Rep. Marjorie Taylor Greene , a Republican from Georgia and staunch Trump ally, in July accused Israel of “genocide” in Gaza.

Trump, meanwhile, doesn’t want a public break with Netanyahu. He is proud of his close ties to Netanyahu and support for Israel, U.S. officials said. He often boasts about the Abraham Accords brokered during his first term, and continues to push for renewed ties between Israel and Saudi Arabia, a grand diplomatic prize he openly covets.

Netanyahu also finds ways to ingratiate himself with Trump’s inner circle and flatter the president directly. On Saturday, Netanyahu, alongside U.S. Ambassador to Israel Mike Huckabee , participated in a cornerstone-laying ceremony to name a promenade in the beachside city of Bat Yam after Trump.

In effect, Netanyahu has shaped a relationship where he can temporarily risk Trump’s ire, knowing it won’t last. Netanyahu has frequently referred to Trump as “the best friend Israel has ever had in the White House.”

“Netanyahu knows that while the White House may grumble a bit, there really is no downside to an ‘ask forgiveness, not permission’ approach,” said Damian Murphy , a former staff director for Democrats on the Senate Foreign Relations Committee.

After the Qatar strike, Trump held two phone calls with Netanyahu , the first to express his displeasure and the second to have a friendlier conversation about whether Israel’s attack was successful. Trump later spoke with the leaders of Qatar, praising the country for its mediation of Israel-Hamas negotiations and for being a staunch U.S. ally that hosts a large American military presence in the Middle East.

Netanyahu insists the war can end only after Hamas lays down its arms and releases the remaining 48 hostages, and the U.S.-designated terrorist group’s leadership leaves Gaza. If Hamas doesn’t accede to those demands, Israel will compel the group’s complete surrender with aerial and ground assaults, a strategy not aligned with Trump’s vision of a negotiated end to the nearly two-year conflict.

Yet Trump’s only overt pressure has been on Hamas, which attacked Israel on Oct. 7, 2023, sparking the war. He has issued repeated warnings that the group will face more violence.

Rubio traveled to Israel this week to engage directly with Netanyahu , but offered no new criticism of Israel for the strike. Netanyahu pointedly refused to rule out striking neighboring countries in the future to target Hamas, which has members involved in cease-fire negotiations in Egypt and Turkey.

Netanyahu said the country has long targeted on foreign soil people whom it holds responsible for terrorist attacks on Israel: “This is the principle we established. It’s a principle we follow. It hasn’t changed.”

The Qatar strike came at an inopportune time for the U.S.

Trump heads to the U.N. General Assembly next week to deliver a speech expected to touch upon his peacemaking efforts. In the weeks leading up to the event, the Trump administration has failed to dissuade allies such as the U.K., France, and Canada from plans to recognize Palestinian statehood, a decision the U.S. says hinders peace efforts by boosting Hamas.

“There will be an Israeli counterreaction to those moves, and we’ve seen some of that happen as well,” Rubio said Monday alongside Netanyahu. The statement came hours before Israel launched a renewed offensive in Gaza City to dismantle what Netanyahu says is Hamas’s “last important stronghold” and as Israel weighs annexing parts of the occupied West Bank.

Trump said last week that he wasn’t informed ahead of Israel’s strike in Qatar. Last week, White House press secretary Karoline Leavitt announced that Trump learned about the operation from the U.S. military, which tracked Israel’s attack in real time.

Trump then asked his personal envoy, Steve Witkoff , to inform the Qataris, but his notification arrived after Israel dropped bombs in Doha, the kingdom’s capital.

Ultimately, however, the biggest problem with the Qatar strike may have been that it wasn’t successful, said Michael Oren , former Israeli ambassador to the U.S. under Netanyahu. Israel targeted Hamas’s top negotiators but instead killed six lower-level representatives, the group said.

“The chances are, if our operation in Doha succeeded, Trump wouldn’t have condemned it, he would have taken credit for it,” Oren said. “He likes winners.”

That same logic might apply to Gaza.

“There has to be someone standing with an Israeli flag saying we won,” Oren said. “I think Bibi understands this about Trump.”

Write to Alexander Ward at alex.ward@wsj.com and Dov Lieber at dov.lieber@wsj.com