President Obama walks with Saudi King Salman in Riyadh on Wednesday. (Kevin Lamarque/Reuters)

President Obama has visited Saudi Arabia more often than any of his predecessors, but his fourth trip to the kingdom on Wednesday seemed less a sign of the strength of the relationship than of its fraught nature.

Obama met first with Saudi King Salman, and on Thursday he will take part in a regional meeting with the United States’ Arab allies in the Persian Gulf. But the backdrop to the visit is a broad recognition that the U.S.-Saudi alliance, long built around oil and security, appears to be in flux and that neither side seems certain what they want out of it.

Obama and the Saudi leaders have diverged sharply at times over how to calm the sectarian tensions roiling the region, how to resolve civil wars in Yemen and Syria, and how to deal with Iran’s influence.

Adding to those tensions is the recently resurrected specter of the attacks of Sept. 11, 2001, and long-classified documents from a congressional report suggesting that the Saudis may have played a role in the attacks.

Renewed scrutiny in allegations that Saudi officials in some way supported the 9/11 terrorist attacks fifteen years ago could make Obama’s trip a complicated one. (Adam Taylor,Jason Aldag/The Washington Post)

A bill that could make Saudi Arabia liable for any role in the terrorist attacks is drawing support from both Republicans and Democrats, even as the Obama administration has lobbied against it. In Saudi Arabia, senior officials are furious about the possible revival of a matter they thought had been settled long ago.

The controversial legislation wasn’t a subject of the two-hour discussion between Obama and the king, which aides described as the longest meeting Obama has had with the Saudi monarch. Instead, the two talked more broadly about the friction in the relationship on issues such as the president’s outreach to Iran and the Saudi insistence that the United States should act to remove Syrian President Bashar al-Assad from power, administration officials said.

Obama, meanwhile, urged the Saudis to seek some kind of accommodation with Iran that would help to defuse the sectarian strife and proxy wars that have led to humanitarian disasters and failed states in the Middle East.

The unusually long meeting between the two leaders reflected a broad and shared uncertainty about where an alliance previously built around Saudi oil and American arms is headed.

“For many years, the basic interest at the root of the U.S.-Saudi relationship was that they provided the oil that sustained the global economy and we provided essential security for the Saudi state, and we really didn’t think of any other aspect of it at great length,” Ben Rhodes, a deputy national security adviser, said in a podcast interview with former top Obama aide David Axelrod. “We just kind of thought about security and oil, and we didn’t go that other layer down.”

For Obama, the next two days here will be part of an ongoing effort to set the relationship with the Saudis on more solid ground and emphasize the two nations’ common interests.

President Barack Obama is escorted to Marine One as he arrives at King Khalid International Airport in Riyadh, Saudi Arabia, Wednesday. (Carolyn Kaster/AP)

The Obama administration has sold the Saudis more than $95 billion in military hardware over the past several years, and Saudi intelligence has been essential to the counterterrorism fight against al-Qaeda and the Islamic State, officials said.

Obama said in an interview with CBS News this week that he expects that Iraqi forces, backed by American advisers and air power, will push the Islamic State out of Mosul, the largest city in northern Iraq, by the end of the year.

Saudi money and relationships with the Sunni tribes in northern and western Iraq will be essential to rebuilding the city and forging a peace in northern Iraq. White House officials said Obama urged the Saudis to help persuade their Sunni brethren to support the embattled government of Iraqi Prime Minister Haider al-Abadi and to help fund the reconstruction of areas freed from the Islamic State,

Obama insisted to the Saudis, who have bristled at his public criticisms of the kingdom, that his repeat visits were evidence of the importance he placed on the U.S.-Saudi relationship.

“Saudi Arabia and America are not getting divorced,” said Bruce Riedel, a former foreign policy adviser to Obama and a senior analyst at the Brookings Institution. “We still need each other.”

Both sides, though, seem to want to move forward on different terms.

Obama has said he wants the Saudis and the gulf allies play a greater role in maintaining their own security and the security of the region.

The Saudis have suggested publicly that they have become too dependent on American firepower, and both King Salman and his son, Defense Minister Mohammed bin Salman, 30, have vowed to take a bolder approach to the region.

The problem has been one of execution.

The Saudi air campaign in neighboring Yemen has led to hundreds of civilian casualties, shifted attention from the fight against the local al-Qaeda affiliate and failed to dislodge rebels from the capital, Sanaa. Saudi Arabia and its allies seek to restore the government ousted in early 2015 by the Houthi rebel fighters, who Saudi leaders say are backed by Iran.

The execution of dozens of terrorism suspects, including a leading Shiite cleric earlier this year, has further inflamed sectarian tensions at a moment when the region can ill afford it. Aides said that Obama and the king had a longer-than-anticipated discussion on Saudi Arabia’s human rights record.

“We want the gulf to be more responsible for their own security affairs, but we’ve seen instead this . . . very worrisome power projection from Saudi Arabia that is inflaming sectarianism,” said Frederic Wehrey, a senior associate in the Middle East Program at the Carnegie Endowment for International Peace. “It’s sort of like this Catch-22, where we want them to do it. But then, when they do it, they do it in ways that is both militarily ineffective and also regionally destabilizing. It’s a conundrum.”

The disagreement between the two nations extends to Obama’s historic accord with Iran to curb its nuclear program, which the president has said will keep Iran from obtaining a nuclear weapon and prevent another American war in the Middle East.

“We would argue that the removal of the threat of a nuclear-armed Iran is good for the United States and the [gulf allies],” Rhodes said.

In Saudi Arabia, the deal is considered part of a broader American pivot toward Iran — a point of view that even billions more in American arms sales, designed to protect Saudi Arabia from Iran, will not completely erase.