After plunging American foreign policy into confusion and disarray, the Trump administration in recent days has embarked on a major damage-control operation.

Earlier this week, President Trump replaced Michael Flynn, the combustible campaign loyalist who resigned after misleading Vice President-elect Mike Pence about his contacts with the Russian ambassador, with Lt. Gen. H.R. McMaster, an active-duty officer and military scholar recommended by members of Congress.

Pence met in Brussels with NATO officials to reassure them of the administration’s “unwavering” commitment to the alliance that Trump called “obsolete” during last year’s campaign. Secretary of Defense James N. Mattis, on his way to Baghdad this week, said that, contrary to what Trump has said, “We’re not in Iraq to seize anybody’s oil.”

Nikki Haley, the U.S. representative to the United Nations, has reaffirmed U.S. support for the two-state solution to the Israeli-Palestinian conflict, despite the president’s breezy exclamation at a news conference with Israel’s prime minister that he “can live with” a one-state solution that he did not define and which seems highly unlikely to offer a feasible pathway to peace.

These attempts to right the shaky ship of state are welcome. The question is whether they represent anything more than a momentary victory for the forces of caution and continuity.

The concern isn’t just about Trump’s unpredictable, impulsive personality or his undisciplined habit of mind. There is also the fact that some of his problematic positions were signature themes of his campaign and might be difficult to discard. That is certainly true of his fixation on “radical Islamic terrorism,” which seems to blur into hostility toward Islam and already has resulted in his disastrous executive order on immigration that has been held up in the federal courts.

A related problem is that some of Trump’s more outlandish ideas also animate some of his White House advisers, who constitute a shadow foreign policy apparatus and who might press for initiatives that seasoned and more expert advisers might counsel against, such as declaring the Muslim Brotherhood a terrorist organization or suddenly moving the U.S. embassy from Tel Aviv to Jerusalem.

On other matters, however, Trump might be able to remain basically true to his campaign themes without causing a rupture in foreign policy. Take his position on NATO. Even during the campaign, he had begun to hedge on his assertion that the alliance was “obsolete.” This week, Pence demanded — as the Obama administration had in the past — that NATO member states contribute 2 percent of their gross domestic product to the alliance. Pence set a deadline of “real progress” — not 100 percent compliance — “by the end of 2017.”

So far, Trump hasn’t followed through on a campaign promise to try to renegotiate the international agreement that placed limits on Iran’s nuclear program in exchange for the lifting of economic sanctions, a deal he denounced as a “disaster.” But he has imposed new sanctions on Iran for the testing of a ballistic missile, which the U.S. sees as a violation of a U.N. Security Council resolution. He can credibly argue both that he is being tough on Iran and that he is taking the advice of the experienced advisers he has chosen to counsel him. More such listening (and less tweeting) should be the president’s program for the next few months.