Attorney General William Barr announced Monday that 21 Saudi service members training at U.S. military facilities will be expelled from the country following an investigation into a deadly shooting at a Naval Air Station in Pensacola, Florida that he called “an act of terrorism.” The Saudi nationals will be removed from the training program after the FBI found they had social media containing “jihadi or anti-American sentiment” or contact with child pornography— or in some cases, both, Barr said.

The December 6 shooting, which killed three U.S. sailors and wounded eight other Americans, triggered a review to find out how a service member from one of the oldest American allies in the Middle East could carry out such an attack. During the course of the probe, investigators found some anti-American beliefs held among Saudi cadets enrolled in a training program at the base. And while there wasn’t any evidence that the 21 service members since kicked out of the program had advance knowledge or coordination with the attack, a total of 17 had shared social media posts containing some “jihadi or anti-American content,” Barr said.

The discovery highlights the latest twist in the strange, turbulent relationship between the U.S. and Saudi Arabia, based on a delicate balance of economic interests for decades. The 77-year alliance between Washington and Riyadh has always been built on a fundamental arrangement: American demand for Saudi oil and Saudi demand for American firepower. But the relationship had soured in recent years under the Obama Administration, which signed the multi-lateral nuclear deal with Iran and briefly halted weapon sales.

Under President Donald Trump’s leadership, this economic bond between the two countries has largely won out over any moral opprobrium. Trump has been unable to rein in Crown Prince Mohammed Bin Salman’s military adventurism in the region and failed to inflict any cost for 2018 killing Jamal Khashoggi, the Saudi journalist and American resident. He has dismissed calls to end arms sales, roll back defense partnerships or review the diplomatic relationship with the Saudis despite repeated calls by Republicans and Democrats alike.

At the Department of Justice headquarters on Monday, Barr praised Saudi Arabia for its cooperation with the U.S. in its investigation of the shooting. “The Kingdom of Saudi Arabia gave complete and total support for our counter-terrorism investigation, and ordered all Saudi trainees to fully cooperate,” Barr said. “This assistance was critical to helping the FBI determine whether anyone assisted the shooter in the attack.”

When asked to clarify whether the United States or Saudi Arabia made the decision to expel the cadets from the program, a senior Justice Department official said that Saudi Arabia “recognized” that this conduct was “unbecoming of an officer in the Royal Saudi Air Force and Navy, and the Department of Defense agreed with that decision.”

FBI investigators found the shooter, Saudi Air Force 2nd Lt. Mohammed Alshamrani, posted a message on social media on Sept. 11 of last year that said: “The countdown has begun.” Then, over Thanksgiving weekend, he visited the 9/11 Memorial in New York City. “He also posted other anti-American, anti-Israeli, and jihadi messages on social media, and did so two hours before his attack at the naval base,” Barr told reporters.

Alshamrani, like all foreign military trainees, passed a vetting process that examined possible links to terrorism, corruption and other criminal behavior before being allowed in the United States. The process has garnered fresh scrutiny in the wake of the shooting, and Barr acknowledged Monday that the vetting the candidates needed improvement.

But he also acknowledged that the training mission remains an essential element of the Saudi-U.S. relationship. “The Royal Saudi Air Force, which flies American-made aircraft, is an important military partner, and has long had a training relationship with us,” Barr said.

Year-in and year-out, Saudi Arabia buys more American weapons than any other country. The Pentagon has a team of U.S. service members in Saudi Arabia wholly dedicated to the “management and administration of Saudi Arabian Foreign Military Sales,” according to the U.S. military documents. It serves as a direct pipeline to move weapons from U.S. arms manufacturers into the arms of the Saudi military. The U.S. military’s Joint Advisory Division works alongside Saudi commanders to help fill their weapons needs.

Once the Saudis commit to what they want — tanks, attack helicopters, missiles, ships, laser-guided bombs — the arms packages must be approved by the U.S. Defense and State Departments, and Congress. The arrangement falls under the U.S. Military Training Mission to Saudi Arabia, which is led by a two-star American general. The mission is primarily designed to bolster Saudi Arabia against arch-rival Iran in order to assert power and influence in the Middle East.

Saudi pilots and service members need to be trained on how to operate the weaponry. More than 28,000 Saudi Arabian international military students have been trained by the United States, according to the Pentagon. Alshamrani was one of 852 Saudis receiving military training in the U.S. on when he opened fire in a Pensacola classroom.

Trump, who is no stranger for criticizing both friends and allies, has maintained support of Saudi Arabia. The President has not only pursued a tighter alliance with the kingdom and embraced it as a bulwark against a surging Iran; he has also invested deeply in the crown prince personally, tweeting reassurances through a string of controversies.

Trump refused Congress’s calls to halt arms sales to Saudi after Khashoggi’s murder, saying in October 2018, “I don’t like the concept of stopping an investment of $110 billion into the United States.” Since the spring, Trump has recently been sending more U.S. troops to the region to help protect Saudi Arabia from Iran. The Trump Administration began boosting troop presence in the region in May after U.S. intelligence indicated “troubling, escalatory and dangerous” behavior by Iran. Since then, the Pentagon deployed about 18,000 additional troops to the Persian Gulf, including 3,500 to Saudi Arabia. The White House also moved ahead with $8.1 billion in weapons sales to Saudi Arabia and other Arab allies, despite Congressional objections.

Trump told Fox News last week that “Saudi Arabia is paying” for U.S. troops deployed to the country. “We have a very good relationship with Saudi Arabia,” Trump said. “I said, ‘Listen, you’re a very rich country. You want more troops? I’m going to send them to you, but you’ve got to pay us.’ They’re paying us. They’ve already deposited $1 billion in the bank.”

The comment brought criticism that Trump was treating U.S. forces as if they were guns-for-hire, echoing the condemnation from Congress when Trump dismissed calls in to halt future arms sales after Khashoggi’s death.

The inability to call the Saudis out throws the future of the Saudi American relationship in more doubt today than ever, says Bruce Riedel, a former Middle East analyst at the CIA now at the Brookings Institution. “The Trump rapture with the Saudis, especially after the Khashoggi murder, has hurt the relationship,” he says. “The toxic embrace of Donald Trump has alienated the Democrats and many Republicans.”

Get our Politics Newsletter. The headlines out of Washington never seem to slow. Subscribe to The D.C. Brief to make sense of what matters most. Please enter a valid email address. Sign Up Now Check the box if you do not wish to receive promotional offers via email from TIME. You can unsubscribe at any time. By signing up you are agreeing to our Terms of Use and Privacy Policy . This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply. Thank you! For your security, we've sent a confirmation email to the address you entered. Click the link to confirm your subscription and begin receiving our newsletters. If you don't get the confirmation within 10 minutes, please check your spam folder.

Write to W.J. Hennigan at william.hennigan@time.com and Tessa Berenson at tessa.berenson@time.com.