The economic pressures on the Saudi state are likely to get worse. Close to seventy per cent of the population is under thirty years old. Every year, the government pays for as many as seventy thousand young people to study in the United States. Those students return home wanting jobs and, often, at least some of the freedoms that they enjoyed in the West.

To address these concerns, M.B.S. devised a plan, called Vision 2030, for a vast transformation of the Saudi economy and society. Working with consultants from McKinsey & Co., he set quantifiable goals to be met in the next decade. The new order would encourage entrepreneurship and foreign investment, and privatize state-owned industries, including the oil business. The workforce would be augmented by a growing number of women, along with nonprofit organizations and civic-minded volunteers. To publicize the plan, M.B.S. travelled to China, to Russia, and to the U.S., where he met with an array of tech executives, including Mark Zuckerberg. At a gathering of prominent venture capitalists at the Fairmont Hotel, in San Francisco, M.B.S. spoke bluntly about Saudi Arabia’s prospects. According to one attendee, he said, “In twenty years, oil goes to zero, and then renewables take over. I have twenty years to reorient my country and launch it into the future.”

The attendee said, “My jaw was on the floor. The meeting had the dynamic of a tech startup. He’s throwing the harpoon.”

M.B.S.’s appointments also allowed him to display his apparently irrepressible ambition. In April, 2016, when President Obama paid his final visit to Saudi Arabia, he and King Salman sat facing each other, with their aides grouped around them. Obama’s advisers noticed that, each time the President spoke, Salman, who was eighty, paused before answering, while M.B.S., several seats to his left, typed on an iPad. When M.B.S. finished, the King read from an iPad of his own and then responded to Obama. “The chances of that being a coincidence are quite low,” a former national-security official told me.

At another meeting, Obama upbraided King Salman for arresting dissident bloggers and for executing Shiite protesters, complaining that these practices made it difficult for him to defend the Saudis in the United States. According to several former American officials, M.B.S. rose abruptly from his chair to convey his displeasure to Obama. “Suddenly, he was standing up and saying, ‘You don’t understand our judicial system—we can get you a briefing,’ ” the former national-security official said. “It was very strange.”

When King Salman named bin Nayef crown prince, some Saudis speculated that the King envisioned him as a sort of caretaker, running the government until M.B.S. could be installed. “I don’t think Salman ever intended to make bin Nayef king,” a prominent Saudi analyst told me. “I think he was just waiting for the moment when M.B.S. was ready.” But bin Nayef was a popular figure, and bypassing him would have aroused resistance within the royal family. Outwardly, M.B.S. and bin Nayef worked smoothly together. M.B.S. adhered carefully to royal protocol; at meetings with foreign leaders, he sometimes asked bin Nayef’s permission to speak. In 2016, Joseph Westphal asked M.B.S. who he thought would succeed King Salman. “He said, ‘We have a crown prince, and historically the crown prince always becomes the king,’ ” Westphal told me.

Under the surface, though, tensions grew, as M.B.S. maneuvered to reduce his rival’s power. His directorship of the economy and of the military allowed him to crowd out bin Nayef’s daily duties. In the name of streamlining the government, he eliminated a council of advisers who answered to bin Nayef, depriving him of most of his professional staff. A former American official who maintains contacts in the region told me, “M.B.S. was literally signing orders in the King’s name.”

Saudi Arabia sees itself as the center of the Islamic world: the king is customarily known as the “custodian of the two holy mosques,” the sacred sites in Mecca and Medina. But, as M.B.S. gained power, he was aided by an ally from outside the kingdom: Mohammed bin Zayed, of the United Arab Emirates. Bin Zayed, or M.B.Z., is the crown prince of Abu Dhabi, the most politically important of the country’s seven emirates. Flush with revenue from oil and from the booming city-state of Dubai, M.B.Z., the country’s de-facto leader, has helped build the Emirates into a kind of Middle Eastern Singapore: rich, efficient, and authoritarian.

M.B.Z., fifty-seven, is a former military helicopter pilot, with a modest bearing that belies his influence throughout the Middle East. “If you sit down to talk to M.B.Z., he’s going to whisper, and he’s going to be very respectful and very polite,” Richard Clarke, a counterterrorism adviser to Presidents Obama and George W. Bush, told me. “You really have to get into his confidence over many years before he will raise his voice. And then he’ll argue with you.” He is unabashedly pro-American in a region teeming with anti-American sentiment; he has purchased billions of dollars’ worth of American weapons and has often been called on to advance U.S. prerogatives. In 2003, the U.A.E. volunteered to send a small contingent of troops to assist in Afghanistan, the first Arab country to do so; fifteen years later, they are still there.

Saudi Arabia and the U.A.E., which share a border, are both hereditary monarchies, dominated by Sunnis, and their interests often align. In foreign affairs, Saudis prefer to see the U.A.E. as their junior partner, but, in many respects, it is M.B.Z. who drives the policy. From early on, he opposed bin Nayef’s rise, in part because of an unresolvable dispute between the two men. In a 2003 U.S. diplomatic cable, published by WikiLeaks, M.B.Z. was quoted comparing bin Nayef’s father to an ape, suggesting that he provided evidence that “Darwin was right.” The former American official with contacts in the region told me, “After that, there was no possibility of a relationship between M.B.Z. and bin Nayef.”

More important, M.B.Z. saw M.B.S. as a younger version of himself: smart, energetic, and eager to confront enemies. As M.B.S. was being groomed for power, the Gulf states were feeling increasingly vulnerable. When the Arab Spring erupted, in 2011, it forced out dictators in Tunisia, Egypt, and elsewhere. Leaders in Saudi Arabia and the Emirates were terrified that their monarchies would soon follow. The emergence of ISIS further alarmed them, and the two countries supported proxies to fight against its incursions in Syria and in Libya. But their most decisive intervention came in Egypt, the Arab world’s most populous country, where the longtime strongman Hosni Mubarak was ousted by a popular uprising. In June, 2012, Egyptian voters delivered the Presidency to Mohamed Morsi, of the Muslim Brotherhood. For the Saudis and the Emiratis, it was a nightmare.

The Brotherhood, founded in 1928, is the world’s largest Islamist movement, with hundreds of millions of followers. It has inspired Islamist political parties throughout the Sunni Muslim world, including branches in Jordan, Syria, and Bahrain. In Egypt, security services had savagely repressed the Brotherhood for decades. After the Arab Spring, though, it emerged as the country’s most organized political force.

“When Morsi got elected, the Saudis and the Emiratis went into overdrive,” a former senior American diplomat told me. According to several former American officials, M.B.Z. and Bandar bin Sultan, the director of Saudi intelligence, began plotting with others in their governments to remove Morsi from power. Egypt’s generals were already organizing against him. Bandar and M.B.Z. reached out to the Egyptian defense minister, General Abdel Fattah El-Sisi, and promised twenty billion dollars in economic aid if Morsi were deposed. (The Emirati Embassy did not respond to requests for comment.) They also began financing an anti-government movement in Cairo, built around an ostensibly independent youth group called Tamarod. As the coup took shape, Bandar and Sisi used Mohammed Dahlan, a Palestinian confidant, to carry messages and money to collaborators in the Egyptian military. The former diplomat said that the foreign support was crucial to the coup: “For Sisi to move like that, he needed a promise that he would succeed.” In July, 2013, the Egyptian military forced Morsi from power, and soon afterward it orchestrated a crackdown on suspected Brotherhood supporters, detaining at least forty thousand people. “It was terrible, terrible,” the diplomat told me. “What the Saudis and the Emiratis did was unforgivable.”