President Barack Obama has never had a great relationship with Saudi Arabia.

Now, he’s the last man standing between the wealthy desert kingdom and billions of dollars in potential liabilities.

Story Continued Below

Obama has cast the Saudis as "so-called" allies; bemoaned the terrorist-inspiring version of Islam they practice; and even suggested the oil-rich Arab state learn to "share" the Middle East with rival Iran. The Saudis, meanwhile, consider Obama naive, sparring with him over the Iran nuclear deal and questioning his hands-off approach to Syria’s bloody civil war.

Despite these differences, Obama has promised to veto a bill that Congress passed unanimously allowing families of 9/11 victims to sue Saudi Arabia over alleged links to the 2001 terrorist attacks.

That Obama and Riyadh find themselves on the same side against Congress underscores the bizarre evolution of U.S.-Saudi ties over the past eight years. An alliance once unquestioned in Washington now faces an extraordinary level of criticism, but the two countries still need each other enough that a breakup is simply not in the cards.

"This is clearly a relationship in transition," said Jon Alterman, an analyst with the Center for Strategic and International Studies. "Nobody really has a sense of what they’re trying to transition it to."

Just how tricky is the relationship? Two more examples: Obama is supporting the Saudis in their fight against Iran-backed rebels in Yemen, even though U.S. officials worry the fight there is distracting from the more important battle against the Islamic State. Andmany of the same U.S. lawmakers happy to make it easier to sue the Saudis just this week green-lit a $1.15 billion arms sale to the country. "Does no one sense the irony?” asked Republican Sen. Rand Paul of Kentucky, one of a handful of lawmakers who tried to block the weapons dealin the Senate.

The back and forth in Washington is "schizophrenic behavior" that has deeply frustrated leaders in the Middle East for years, said a former senior U.S. official deeply familiar with the Arab world.

Congress passed the lawsuit bill under intense pressure from families of victims and just ahead of the 15th anniversary of the Sept. 11 attacks. The Saudis, through direct contacts as well as a powerful set of lobbyists, have tried hard to stop it, waging a major PR effort that included releasing a white paper detailing the kingdom's efforts to stop terrorists. The Saudis deny any government role in the attacks and note that the U.S. has never found proof of it, either. The Saudis also have warned they will sell off billions of dollars in U.S. assets to protect themselves against lawsuits.

Administration officials downplay the idea that Obama will veto the bill merely to protect Saudi Arabia. Normally, U.S. citizens aren't allowed to sue foreign governments under the concept of sovereign immunity. Obama's concern, officials say, thus goes well beyond the Saudis; he's worried that the bill erodes the sovereign immunity principle and could lead other countries to allow the U.S. to be sued over its actions abroad.

"To pass a piece of legislation that would open up our diplomats and our service members and even American businesses to potential lawsuits in courts all around the world is foolish," White House spokesman Josh Earnest said in a recent press briefing.

The perception in many quarters, however, is that Obama is coming to the aid of a country with much to hide. Fifteen of the 19 hijackers on Sept. 11, 2001, were Saudi nationals. And the recent declassification of roughly 30 pages from a 2002 congressional probe into the 9/11 attacks raised more questions about Saudi government ties to Islamist extremists.

"We are disappointed that the president is not standing with us," said Mindy Kleinberg, who lost her husband in the attacks and was meeting with lawmakers Thursday to push for a veto override. "We have been waiting a very long time for justice, and we feel that this bill will go a long way toward accountability."

Whatever his motivation, Obama's decision to veto the bill is unlikely to do much to ease Saudi suspicions.

The Saudis' wariness of Obama has its roots in his comments in 2002, well before he ran for president, referring to the monarchy in Riyadh as a so-called ally. It grew after Obama sided against Egyptian strongman Hosni Mubarak during the 2011 Arab Spring movements, leading Saudi royals to question whether America would have their backs in a domestic political crisis of their own.

It deepened in 2013, after Obama decided not to stage a military strike against Syrian President Bashar Assad, who is despised by the Saudis, even after Assad apparently crossed Obama's "red line" by using chemical weapons. And it reached a new peak in 2015 after Obama struck a nuclear deal with Iran, a Shiite theocracy that Sunni-majority Saudi Arabia views as a growing threat in the Middle East.

Still, Obama, cognizant of the need for the U.S. to maintain alliances with stable countries in the Middle East, has otherwise tried hard to allay Saudi concerns. He cut short a trip to India to rush to see the newly crowned Saudi king, Salman, in January 2015, after the previous monarch died. He also has pushed for new weapons and other security agreements with the Saudis, in part to assuage Saudi concerns about the Iran nuclear deal.

But earlier this year, in comments to the Atlantic magazine that infuriated the Saudis, Obama appeared to reverse decades of U.S. policy that tilted heavily toward Riyadh and against Tehran.

“The competition between the Saudis and the Iranians — which has helped to feed proxy wars and chaos in Syria and Iraq and Yemen — requires us to say to our friends as well as to the Iranians that they need to find an effective way to share the neighborhood and institute some sort of cold peace,” Obama said.

Prince Turki Al-Faisal, the former head of Saudi intelligence, wrote in an extraordinary open letter soon afterward that Obama had "thrown us a curve ball" and criticizing the president for saying America’s Gulf allies were “free riders” wholly dependent on the U.S. for their security.

And in April, weeks after the Atlantic piece was published, Saudi Arabia appeared to snub Obama when he visited Riyadh for a summit by sending a lower-level official to greet him at the airport and not broadcasting his arrival on state TV. The readouts from those meetings in Riyadh also suggested the president hadn't done much to assuage Saudi concerns, with the two sides saying they'd "discussed" and "exchanged views" more than agreeing on anything.

The president also hosted Saudi Arabia’s deputy crown prince, Mohammed Bin Salman, when he visited Washington this summer on a trip aimed at improving the kingdom’s image in Washington. Obama made sure to praise the prince's plan to transform the Saudi economy, dubbed Vision 2030. He also tried to reassure the Saudi royal that the U.S. will back the Saudis against interference by Iran, which remains an official enemy of the United States.

But some constants in the U.S.-Saudi relationship have turned into variables, meaning that even after Obama leaves office in just a few months, the alliance could prove rocky.

The low price of oil, for example, is forcing the kingdom to rethink its economy; the U.S. also relies more now on its own energy reserves, reducing America’s addiction to Saudi oil. Some observers also point to cultural changes in deeply conservative Saudi Arabia — women, though still facing severe segregation, make up a growing share of the workforce; young people are more exposed than ever to the Internet and the outside world; and thousands of Saudis educated in the U.S. are now capitalizing on that experience in their country.

By all accounts, the U.S. and Saudi Arabia still maintain a strong security relationship, and U.S. officials privately say the Saudis are helpful partners in the fight against terrorist groups such as Al Qaeda, which the Saudi monarchy views as a threat to its own rule. U.S. officials also say the Saudis have taken steps in recent years to silence the most radical of their Islamist preachers and change their school curricula to be more tolerant.

"The close cooperation on countering violent extremists like [the Islamic State], the continued Saudi preference for American arms, the important role that Saudi Arabia plays in international energy markets and the $70 billion dollars worth of annual trade between the two countries are enough to sustain this relationship for the foreseeable future," said Fahad Nazer, a former political analyst with the Saudi Embassy in Washington who now does similar work for JTG Inc.

In many ways, what Obama thinks about the Saudis matters less and less as his time in the Oval Office draws to an end. But while the Saudis will be happy to see him leave, there's great uncertainty in Riyadh about how the next president will deal with them.

Both Democrat Hillary Clinton and Republican Donald Trump have voiced grave concerns about Saudi Arabia's track record of producing Islamic extremists; Clinton has said she supports the 9/11 lawsuit bill. But while Clinton would likely be a more predictable partner, the Saudis see Trump — who has called for a ban on Muslims entering the United States — as a wild card.

For now, however, the Saudis are nervously watching Congress to see exactly how unhappy lawmakers are with them.

Already, some members of Congress are hinting that they are not comfortable with the 9/11 legislation after all, and that they may consider voting to uphold Obama's veto. Their hesitation comes as a growing number of foreign countries and blocs, including the European Union, voice opposition to the bill. The original bill passed on voice vote in both Houses, making a veto override especially sensitive because members will have to go on the record. And with the presidential election looming, the politics are even more fraught than normal.

“Saudi Arabia has never been an especially popular actor in Washington — a powerful one, but not popular," the former senior U.S. official said. "And now, nobody in Congress wants to stick their neck out for the Saudis two-and-a-half months before the presidential election.”