WASHINGTON — The United States announced charges Wednesday against two Russian intelligence officers and two hackers, accusing them of a mega data breach at Yahoo that affected at least a half billion user accounts.

The hack targeted the email accounts of Russian and U.S. officials, Russian journalists, and employees of financial services and other businesses, officials said.

"We will not allow individuals, groups, nation states or a combination of them to compromise the privacy of our citizens, the economic interests of our companies, or the security of our country," said Acting Assistant Attorney General Mary McCord.

One of the defendants has been taken into custody in Canada, and another is on the list of the FBI's most wanted cyber criminals.

The charges arise from a compromise of Yahoo user accounts that began at least as early as 2014. Though the Justice Department has previously charged Russian hackers with cybercrime — as well as hackers sponsored by the Chinese and Iranian governments — this is the first criminal case brought against Russian government officials.

The announcement comes as federal authorities investigate Russian interference through hacking in the 2016 presidential election.

Yahoo didn't disclose the 2014 breach until last September when it began notifying at least 500 million users that their email addresses, birth dates, answers to security questions and other personal information may have been stolen. Three months later, Yahoo revealed it had uncovered a separate hack in 2013 affecting about 1 billion accounts, including some that were also hit in 2014.

In a statement, Chris Madsen, Yahoo's assistant general counsel and head of global security, thanked law enforcement agencies for their work.

"We're committed to keeping our users and our platforms secure and will continue to engage with law enforcement to combat cybercrime," he said.

The indicted FSB officers are Dmitry Dokuchaev and Igor Sushchin, his superior. The FSB is the Russian intelligence agency. Particularly galling to U.S. officials is that the men worked for the cyber investigative arm of the FSB — a rough equivalent of the FBI's Cyber Division.

Dokuchaev, whose hacker alias was "Forb," was arrested in December in Moscow, according to the news agency Interfax, on charges of state treason for passing information to the CIA. He had reportedly agreed to work for the FSB to avoid prosecution for bank card fraud.

Another man indicted in the case is Alexsey Belan, who is on the most-wanted cyber list and has been charged twice before, in connection with intrusions into three major tech firms in Nevada and California in 2012 and 2013. He was in custody in Greece for a time, but made his way back to Russia, where he is being protected by authorities, officials said.

The other hacker-for-hire is Karim Baratov, who was born in Kazakhstan but has Canadian citizenship. He was arrested in Canada on Tuesday.

The indictments grew out of a nearly two-year investigation by the San Francisco FBI with the aid of international law enforcement, officials said. Sanctions and criminal charges are two tools that the Obama administration began using to punish and deter nation state hackers.

"They have the effect of galvanizing other countries that are watching what's happening," said Luke Dembosky, a former deputy assistant attorney general for national security. "They show that we have the resources and capabilities to identify the people at the keyboard, even in the most sophisticated cases."

Three years ago, the United States brought charges against five Chinese military hackers for economic espionage, marking the first time cyber-related charges were levied against foreign government officials.

After the Chinese military hackers were indicted, officials said their activity seemed to dwindle. And the indictments, Dembosky said, helped wrest a pledge in 2015 from the Chinese to stop economic cyber espionage against U.S. firms.

In early 2015, the Obama administration imposed economic sanctions on North Korea for its cyber attack on Sony Pictures' systems.

And in late December, the Obama administration levied economic sanctions on Moscow for its election-year meddling. At the same time, the government sanctioned two Russian criminal hackers with no apparent connection to the Kremlin's interference campaign. They included Belan, who is one of the four indicted in the Yahoo case.

Information from the Associated Press and Washington Post was used in this report.