The United States has charged two Russian intelligence agents and two criminal hackers with masterminding the 2014 theft of 500 million Yahoo accounts.

This is the first time the US government has criminally charged Russian spies for cyber offences.

The charges came amid controversy relating to alleged Kremlin-backed hacking of the 2016 US presidential election.

There are also controversies over possible links between Russian figures and associates of President Donald Trump, and uncertainty about whether Mr Trump is willing to respond forcefully to aggression from Moscow in cyberspace and elsewhere.

The 47-count Justice Department indictment includes charges of conspiracy, computer fraud and abuse, economic espionage, theft of trade secrets, wire fraud, access device fraud and aggravated identify theft.

It paints a picture of the Russian security services working hand-in-hand with cyber criminals, who helped spies further their intelligence goals in exchange for using the same exploits to make money.

"The criminal conduct at issue, carried out and otherwise facilitated by officers from an FSB unit that serves as the FBI’s point of contact in Moscow on cyber crime matters, is beyond the pale, Acting Assistant Attorney General Mary McCord said at a press conference announcing the charges.

Russia’s Federal Security Service (FSB) is the successor to the KGB.

Yahoo said when it announced the then-unprecedented breach last September that it believed the attack was state-sponsored, and today the company said the indictment "unequivocally shows" that to be the case.

The charges are not related to the hacking of Democratic Party emails during the presidential election.

US intelligence agencies have said they were carried out by Russian spy services, including the FSB, to help the campaign of Mr Trump, the republican candidate.

The indictment named the FSB officers involved as Dmitry Dokuchaev and his superior, Igor Sushchin, who are both in Russia.

Mr Dokuchaev was arrested for treason in December, according to the Russian news agency Interfax.

The alleged criminals involved in the scheme include Alexsey Belan, who is among the FBI's most-wanted cyber criminals and was arrested in Europe in June 2013 but escaped to Russia before he could be extradited to the United States, according to the Justice Department.

Karim Baratov, who was born in Kazakhstan but has Canadian citizenship, was also named in the indictment.

The Justice Department said Mr Baratov was arrested in Canada yesterday.

Mark Pugash of Toronto police later confirmed the arrest.

Ms McCord said the hacking campaign was waged by the FSB to collect intelligence but that the two hackers used the collected information as an opportunity to "line their pockets."

The United States does not have an extradition treaty with Russia, but Ms McCord said she was hopeful Russian authorities would cooperate in bringing criminals to justice.

The United States often charges cyber criminals with the intent of deterring future state-sponsored activity.