During his campaign, Donald Trump’s Middle East policy seemed to begin and end with his vow to “bomb the hell” out of the Islamic State — a pledge that played well with his base but unsettled establishment foreign policy experts, who worried that the collateral damage would include everything else America has been trying to build in the region.

The establishment was giving itself too much credit: Our policies in the Middle East have been blowing themselves up for a good while. As Mr. Trump embarks Friday on his first foreign trip, including stops in Israel and Saudi Arabia, he has a chance to put in place a new long-term vision. In fact, the outlines of one are already in place. Despite the controversies at home, Mr. Trump may come away with a legacy-cementing achievement: a Trump Doctrine for the Middle East.

The Middle East is complex, but Mr. Trump’s predecessors stumbled for a singular reason: the rise of Iran. As a senior official in the George W. Bush administration, I saw firsthand how President Bush’s democracy project in Iraq diverted attention from countering Iran and its proxies. Mr. Bush seems to have believed that a robust democracy in Iraq would serve simultaneously as a bulwark against Sunni Islamic extremism and Iranian power. In the end, Iran slipped into Iraq under Mr. Bush’s nose, subverted the project, and recruited proxy militias to promote its interests.

Mr. Bush let Iran in by miscalculation. President Barack Obama, by contrast, embraced Iranian ascendancy with open arms — and not just in Iraq, but in Syria as well. Mr. Obama dropped efforts to contain Iran and sought a nuclear accord that would allow the West to normalize relations because he was convinced that recognition of an Iranian sphere of influence would persuade Tehran to function as a partner in stabilizing Iraq and Syria. This was another miscalculation, and it led directly to the Russian-Iranian military alliance in Syria.