President Trump’s impetuousness and his simplistic view of American interests have again put national security at risk. He has taken sides with Saudi Arabia and four other Sunni states in their attempt to isolate and bully Qatar, the tiny gulf nation that is arguably America’s most important military outpost in the region.

Rather than position the United States to ease tensions in the Middle East, Mr. Trump has, essentially, picked one side in a small rivalry within a big rivalry. Saudi Arabia, the United Arab Emirates, Egypt, Bahrain and Yemen chose to cut ties to Qatar for a number of reasons, some of them petty, but principally because Qatar has a relatively close relationship with the Sunni states’ greatest rival, Shiite Iran.

Iran is a bad actor in many ways, but it also shares some interests with the United States, including in the fight against the Islamic State. On Wednesday, the Islamic State claimed responsibility for two attacks that killed 12 people in Tehran at the Iranian Parliament and the mausoleum of the Islamic republic’s founder, Ayatollah Ruhollah Khomeini.

Mr. Trump has made clear he seeks no opening to Iran and has no interest in building on the Obama administration’s success in reaching a nuclear deal with it. But even if his goal is to isolate Iran, allying with Saudi Arabia to punish Qatar is a self-defeating way to go about it: Qatar is home to the forward headquarters of the United States Central Command and is a major intelligence hub. It hosts Al Udeid Air Base, with more than 11,000 U.S. and coalition forces.