WASHINGTON—On the first day of his second term, President Trump predicted he would be remembered as a peacemaker and a unifier.

“Our power will stop all wars and bring a new spirit of unity to a world that has been angry, violent and totally unpredictable,” Trump said on Inauguration Day.

About five months later, the world is proving to be more angry, violent and unpredictable than Trump bargained for.

The war in Ukraine , which Trump vowed to end immediately, is grinding on despite his repeated attempts to broker a resolution. Peace in Gaza remains out of reach. And now, Israel’s strikes on Iran threaten to envelop the Middle East in a broader conflagration, potentially dragging the U.S. in to defend its longtime ally.

“Ultimately, reality triumphs over fantasy—sometimes it takes a while,” said John Bolton , who served as a national security adviser to Trump in his first term and became a critic of the president.

“President Trump inherited a world at war from Joe Biden and he is leading with strength to restore peace,” White House press secretary Karoline Leavitt said in a statement, pointing to the return of American hostages from Gaza, a cease-fire between India and Pakistan, a truce with Yemen’s Houthis to suspend airstrikes on ships navigating Middle Eastern waters and backing a deal for a U.S.-led group to take over Panama Canal ports from China. “The president continues to work around the clock to end the Russia-Ukraine conflict, which would have never began if not for Joe Biden’s sheer incompetence, and ensure Iran can never obtain a nuclear weapon.”

The tension in the Middle East has inflamed long-simmering disagreements in Trump’s political base over U.S. intervention in foreign affairs.

“No issue currently divides the right as much as foreign policy,” Charlie Kirk , the conservative activist , said Thursday on X. He added that the conflict between Iran and Israel could “cause a massive schism in MAGA and potentially disrupt our momentum and our insanely successful presidency.”

Trump built his political comeback in part on the failures of the past, including President Joe Biden’s botched withdrawal from Afghanistan. On the campaign trail, Trump claimed that Russia would have never invaded Ukraine on his watch, nor would Hamas have launched the Oct. 7, 2023, attack on Israel.

“I’m proud to be the only president in decades who did not start a new war,” Trump said at the first rally of the recent presidential campaign, boasting that he could reach a settlement between Russia and Ukraine within 24 hours. He later said he was being “a little bit sarcastic” when he made that claim.

Trump argued that his relationships with Russian President Vladimir Putin and Chinese leader Xi Jinping would bring about an era of peace and prosperity. Foreign leaders, even the toughest and most despotic ones, would come to respect—even fear—the U.S. again, he said.

Putin has shown little interest in coming to an agreement with Ukraine or listening to the Trump administration, which is resisting calls for tougher action against Moscow. Trump has since resigned himself to letting Russia and Ukraine exhaust themselves in battle before engaging in peacemaking diplomacy.

Israel, meanwhile, has seized further control of Gaza on Trump’s watch, escalating the war after his incoming administration helped Biden’s team broker a temporary cease-fire in January. Trump helped secure the release of every living American hostage from Hamas’s grasp, but more than 50 people remain in captivity, with 20 of them believed to be alive. Trump has asked Israeli Prime Minister Benjamin Netanyahu to wind down the war and give priority to the freedom of the hostages, but the Israeli leader hasn’t yet shown a willingness to end the conflict.

Now, Israel has launched a sweeping operation known as “Rising Lion,” which has targeted Iran’s nuclear facilities and scientists, as well as military leaders. It is a stunning, maximalist step likely weakening Tehran when it was already reeling from Israeli strikes last year.

Netanyahu said to Trump on Monday that he would authorize the attack. Trump told him to hold off , insisting that the diplomatic approach to dismantling Iran’s nuclear work should play out before turning to a military step. Trump repeated that message in several phone calls this past week, U.S. officials said, but Netanyahu pushed forward.

If the conflict between Israel and Iran deepens, the U.S. might need to send troops and military assets to defend Israel against retaliatory attacks. American military bases and embassies in the region, or even around the world, could be targeted by Iranian proxies.

On Friday, Iran launched dozens of missiles at Israel. Some weapons struck Tel Aviv even as others were intercepted. America’s military assisted with Israeli air defenses, U.S. officials said.

The episode has brought to the surface discord among prominent conservatives.

The longtime conservative commentator and Trump ally Mark Levin has been clashing online with the former Fox News host Tucker Carlson over America’s role in conflicts abroad . Carlson alleges that Levin is “lobbying for war with Iran” and seeking regime change. Levin, in private remarks to the Republican Jewish Coalition on Thursday, said that Carlson is a bully and that bullies deserved to be punched in the face, according to attendees.

The political sensitivities were on display when Israel began its attack. Instead of issuing a statement from Trump, the White House released one from Secretary of State Marco Rubio , which distanced the U.S. from any involvement.

“Tonight, Israel took unilateral action against Iran,” that statement said. “We are not involved in strikes against Iran and our top priority is protecting American forces in the region.”

By Friday morning, Trump delivered a different message. In an interview with The Wall Street Journal, he called the attack successful and asserted that it created better conditions for talks with Iran. “They should have made a deal and they still can make a deal while they have something left—they still can,” he said.

Sen. Lindsey Graham (R., S.C.), a Trump ally, wrote in a social-media post : “If diplomacy fails, going all in for Israel shows that America is back as a reliable ally and a strong force against oppression. It would strengthen our hand in all corners of the world, as well as all other conflicts we face.”

An early question is how the launch of what could be a broader regional war will shape Trump’s legacy. Much depends on what transpires in the days and weeks ahead, said Richard Fontaine , a former foreign-policy adviser to the late Republican Sen. John McCain who is now chief executive of the Center for a New American Security, a think tank.

“If this comes out looking like a defeat for Iran and a victory for Israel and perhaps the United States, few will point out the contradiction with a no-wars pledge,” he said.

Matthew Kroenig , senior director of the Atlantic Council’s Scowcroft Center for Strategy and Security, said it is still possible for Trump to chart a winning political message.

“I think he can go to the traditional Reaganites and say, ‘Peace through strength, we’re not letting evil regimes build nuclear weapons,’ ” he said, “But he can also go to the MAGA folks and say, ‘No Americans were killed, we didn’t do this, and allies are stepping up and taking care of security threats for us.’ ”

That depends on the shape of the conflict in the coming days and whether the U.S. can avoid getting involved—the biggest foreign-policy test so far for Trump.  “We will measure our success not only by the battles we win but also by the wars that we end,” he said during his January inauguration speech. “And perhaps most importantly, the wars we never get into.”

Write to Alex Leary at alex.leary@wsj.com and Alexander Ward at alex.ward@wsj.com