Less than three weeks ago, on his first trip abroad as President, Donald Trump greeted the young Emir of Qatar, Tamim bin Hamad al-Thani, who was swathed in white robes and headdress, with effusive warmth. “We’ve been friends now for a long time, haven’t we?” Trump said. “Our relationship is extremely good.” The President announced that the two leaders would discuss “the purchase of lots of beautiful military equipment, because nobody makes it like the United States. First, that means jobs,” he said, adding, “It also means, frankly, great security back here” in the Gulf. The same day, at the summit in Riyadh, Trump warmly welcomed Qatar into his new coalition of conservative Sunni regimes, designed to confront Islamic extremism and contain Iran.

On Tuesday, in a series of startling and undiplomatic tweets, Trump threw the leader of oil-rich Qatar under the diplomatic bus. Trump’s stunning flip-flop came a day after a toxic split in the Arab world—the biggest in years—as Saudi Arabia led six countries to sever diplomatic and commercial relations with neighboring Qatar.

“During my recent trip to the Middle East I stated that there can no longer be funding of Radical Ideology. Leaders pointed to Qatar - look!” the President tweeted after the Saudi announcement. He not only took sides in an intra-Arab dispute; he sabotaged the cohesion of his own new Sunni coalition—which he touted just last month as an unprecedented foreign-policy success.

Trump followed his tweet with two more that seemed to take credit for the confrontation, even though other U.S. officials later quietly acknowledged that Washington was blindsided by Saudi Arabia’s decision. The President wrote, “So good to see the Saudi Arabia visit with the King and 50 countries already paying off. They said they would take a hard line on funding . . . extremism, and all reference was pointing to Qatar. Perhaps this will be the beginning of the end to the horror of terrorism!”

The Trump-endorsed rupture is a big deal for America’s effort to eradicate ISIS in Iraq and Syria, and for its war in Afghanistan. For fourteen years, no country in the Middle East has provided more pivotal military space to the U.S. than Qatar. Its Al Udeid Air Base was built, in 2003, to U.S. specifications. Throughout its military campaigns across the region, the United States has relied on the facility to coördinate and launch bombing runs on two continents. I’ve visited the sprawling air base during visits by Secretaries of State. Some ten thousand Americans are deployed there. A hundred U.S. warplanes—including the mighty B-52 bomber—are based in Qatar.

“This is essentially the hub from which we manage, plan, and execute air operations from Egypt to Afghanistan,” Lieutenant Colonel Damien Pickart, the Air Force Central Command spokesman in Qatar, told me, on Monday. “Every single hour of every day, we have aircraft that take off and land—three hundred and sixty-five days a year.”

The Arab rupture was sudden and deep. It pits the largest and wealthiest Arab countries against Qatar, one of the region’s smallest nations. Saudi Arabia was joined by Egypt, which accounts for a quarter of the Arab world’s four hundred million people, the United Arab Emirates, Bahrain, Yemen, the Maldives, and one of Libya’s two governments. They closed off air, land, and sea access to Qatar. Their demands ranged from closing Al Jazeera, the news organization based in Qatar, to suggestions of regime change in Doha.

In a statement, the Saudis accused their tiny neighbor of “adopting various terrorist and sectarian groups aimed at destabilising the region including the Muslim Brotherhood Group, Daesh (ISIS) and Al-Qaeda” and of supporting Iran and its proxies. The crisis reflects long-standing differences in regional and world views. Since the mid-nineties, Qatar’s royal family has dared to chart a course that has been increasingly independent—and somewhat outsized—compared with the other five sheikhdoms in the Persian Gulf. It became Saudi Arabia’s most dynamic Arab rival in the region; Saudi Arabia and Qatar have supported competing factions (both Sunni and anti-government) in Syria, too.

During the Arab Spring, Qatar used its vast wealth to nurture, and often to fund, Islamist movements that won elections, notably Egypt’s Muslim Brotherhood. The idea that Qatar tolerated elections at all alarmed authoritarian Saudi Arabia. Qatar had a realpolitik attitude about regional relations, too, pursuing good relations with Iran, with which it shares one of the world’s largest gas fields. Culturally, its women—including the former Emir’s wife and daughter—have played highly visible leadership roles in education and the arts. Qatar opened branches of U.S. universities, including Georgetown, Northwestern, Carnegie Mellon, and Texas A&M.

Core tensions run far deeper, however. The split between Saudi Arabia and Qatar often seems like a Hatfield-and-McCoy feud, with a religious dimension. Both countries practice the same ultra-conservative Wahhabi brand of Islam. Saudi Arabia’s Wahhabi clerics have begun to challenge the Qatari Emir’s religious credentials, according to Bruce Riedel, a Gulf specialist at the Brookings Institution. “The rest of us may not care about this, but it’s a real challenge to the al-Thani monarchy,” he told me. “That’s essentially a call for regime change.”

The impact of the crisis on Qatar, where officials expressed surprise at the abrupt move, was immediate. “Qatar respects the sovereignty of other nations and does not interfere in their internal affairs, and it has fulfilled its role in fighting terrorism and extremism,” the government said, in rebuttal. Qatar has the highest per-capita income in the world, but Saudi Arabia is its only land border, and forty per cent of its food transits from the kingdom. There was an immediate run on Qatari grocery stores. Its high-end airline flies regional and global routes over Saudi airspace; these have had to be rerouted or cancelled.

The Trump Administration was surprised, too, despite the President’s recent visit. On Tuesday, the State Department spokeswoman Heather Nauert said that Washington had only been notified shortly before the formal split, and the notification had come from the United Arab Emirates, not from the Saudis. Middle East experts believe that the Saudi-led move to isolate Qatar was so sweeping that it had to have been in the works long before Trump’s visit.

Trump’s visit to Saudi Arabia—which was a radical reversal after his condemnation of the kingdom during the Presidential campaign—may have empowered the House of Saud. “They came away feeling that they had a blank check to go against their enemies,” Riedel told me. “Instead of going after their big and tough enemies—Iran and Al Qaeda—they went after their little enemy, the one that drives them crazy, Qatar.”

In his tweets, Trump appeared at odds with his own diplomats and military. In April, Defense Secretary James Mattis visited Qatar, where he “reinforced the importance of deepening the U.S.-Qatari strategic partnership,” the Pentagon said, in a statement at the time. On Tuesday, a Pentagon spokesman, Navy Captain Jeff Davis, told reporters, “We continue to be grateful to the Qataris for their longstanding support for our presence and their enduring commitment to regional security.” He said that the Defense Department had no plans to alter its deployment in Qatar.

In Qatar itself, U.S. Ambassador Dana Shell Smith tweeted praise for Qatar’s “real progress to counter terrorist financing.” On a visit to Australia, Secretary of State Rex Tillerson said that the United States recognizes that Qatar “continues to make efforts to stop the financing of terrorist groups,” but added, “There is more work to be done.” He urged the rival nations to “sit down and address these issues.” He also offered to mediate.