SAN FRANCISCO -- Saudi Arabia, frustrated by growing criticism of its leaders and policies on social media, recruited two Twitter employees to spy on thousands of accounts that included prominent opponents, U.S. prosecutors have alleged.

A complaint unsealed Wednesday in U.S. District Court in San Francisco detailed a co-ordinated effort by Saudi government officials to recruit employees at the social media giant to look up the private data of Twitter accounts, including email addresses linked to the accounts and internet protocol addresses that can give up a user's location. It appeared to link Crown Prince Mohammed bin Salman, the powerful 34-year-son of King Salman, to the effort.

The accounts that were looked at included those of a popular Saudi government critic with more than 1 million followers and a news personality, but they were not named in the complaint. It marks the first time that the kingdom, long linked to the U.S. through its massive oil reserves and regional security arrangements, has been accused of spying in America.

The complaint alleged that the employees -- whose jobs did not require access to Twitter users' private information -- were rewarded with a designer watch and tens of thousands of dollars funneled into secret bank accounts. Ahmad Abouammo, a U.S. citizen, and Ali Alzabarah, a Saudi citizen, were charged with acting as agents of Saudi Arabia without registering with the U.S. government.

At his appearance in Seattle federal court on Wednesday, Abouammo was ordered to remain in custody pending a detention hearing set for Friday. Investigators said Alzabarah is in Saudi Arabia.

The Saudi government's embassy in Washington did not comment on the case and its state-run media and affiliated state-linked media did not report on the charges on Wednesday or Thursday.

The allegations against the two former Twitter employees and a third man who ran a social media marketing company that did work for the Saudi royal family comes a little more than a year after the killing of Jamal Khashoggi. The Washington Post columnist and prominent critic of the Saudi government was slain and dismembered in the Saudi consulate in Istanbul.

Saudi Arabia under King Salman and Prince Mohammed has aggressively silenced and detained government critics even as it allowed women to drive and opened movie theatres in the conservative kingdom.

Prince Mohammed also has been implicated by U.S. officials and a United Nations investigative report in the assassination of Khashoggi. The prince has said he bears ultimate responsibility for what happens in the kingdom's name, but he has denied orchestrating the slaying.

The new criminal allegations would seem to show how the Saudi government has tried to control the flow of information on Twitter, said Adam Coogle, a Middle East researcher with Human Rights Watch.

The platform is the main venue for Saudis to express their views, and about a third of the country's 30 million people are active users. But the free-wheeling nature of Twitter is a major source of concern for its authoritarian government, Coogle said.

The kingdom has used different tactics to control speech and keep reformers and others from organizing, including employing troll armies to harass and intimidate users online. It has also arrested and imprisoned Twitter users.

The crown prince's former top adviser, Saud al-Qahtani, who also served as director of the cyber security federation, started the "Black List" hashtag to target critics of the government. He ominously tweeted in 2017 that the government had ways of unmasking anonymous Twitter users.

"If you combine that with what we know about at least these two individuals and what went on in 2014 and into 2015, it's pretty chilling," Coogle said.

Al-Qahtani has been sanctioned for his suspected role in orchestrating the brutal killing of Khashoggi. His Twitter account was suspended in September for violating the platform's manipulation policy.

Twitter acknowledged that it co-operated in the criminal investigation and said in a statement that it restricts access to sensitive account information "to a limited group of trained and vetted employees."

"We understand the incredible risks faced by many who use Twitter to share their perspectives with the world and to hold those in power accountable," the statement said. "We have tools in place to protect their privacy and their ability to do their vital work."

A critic said Twitter didn't live up to its principle of restricting access to information about private individuals to the smallest possible number of employees.

"If Twitter had implemented this principle, this misappropriation of information would not have been possible," said Mike Chapple, who teaches cybersecurity at the University of Notre Dame's Mendoza College of Business.

He added: "Social media companies must understand the sensitivity of this information and restrict access to the smallest possible number of employees. Failing to do so puts the privacy, and even the physical safety, of social media users at risk."

Abouammo was also charged with falsifying documents and making false statements to obstruct FBI investigators -- offences that carry a maximum penalty of 30 years in prison if convicted.

His lawyer, Christopher Black, declined to comment, as did Abouammo's wife, who did not give her name.

The complaint said Abouammo, a media partnership manager for Twitter's Middle East region, and Alzabarah, a Twitter site reliability engineer, worked with an unnamed Saudi official who leads a charitable organization belonging to a person named Royal Family Member 1.

Prosecutors said a third defendant, a Saudi named Ahmed Almutairi who worked as a social media adviser for the Saudi royal family, acted as an intermediary with the Twitter employees.

The complaint said Almutairi recruited Alzabarah and flew him to Washington, D.C., in the spring of 2015, when a Saudi delegation visited the White House.

Based on the context and times mentioned in the complaint, including Alzabarah taking a selfie with the royal while in Washington, it appears Prince Mohammed is that royal. The crown prince had travelled there as part of the delegation while he was serving as deputy crown prince.

"Within one week of returning to San Francisco, Alzabarah began to access without authorization private data of Twitter users en masse," the complaint said.

The effort included the user data of over 6,000 Twitter users, including at least 33 usernames for which Saudi Arabian law enforcement had submitted emergency disclosure requests to Twitter, investigators said.

After being confronted by his supervisors at Twitter, Alzabarah acknowledged accessing user data and said he did it out of curiosity, authorities said.

Alzabarah was placed on administrative leave, his work-owned laptop was seized and he was escorted out of the office. The next day, he flew to Saudi Arabia with his wife and daughter and has not returned to the United States, investigators said.

A warrant for his and Almutairi's arrests were issued as part of the complaint.

--------

Melley reported from Los Angeles. Associated Press writers Jon Gambrell in Dubai, United Arab Emirates, Eugene Johnson in Seattle and Jocelyn Gecker in San Francisco contributed to this report.