The British government says that Russia was behind a massive global cyberattack that hit major companies in June 2017.

Foreign Office minister Tariq Ahmad said in a statement on Thursday that the Russian military was responsible for the attack, which initially targeted computers in Ukraine but quickly spread beyond its borders.

The attack -- called NotPetya -- hit companies including British advertising group WPP (WPP), Oreo maker Mondelez (MDLZ), U.S. drugmaker Merck (MRK) and global shipping company FedEx (FDX).

"The destructive attack masqueraded as ransomware, but its purpose was principally to disrupt," the U.K. government said in a statement.

"The decision to publicly attribute this incident reiterates the position of the U.K. and its allies that malicious cyber activity will not be tolerated," it added.

The White House called the cyber-attack "reckless and indiscriminate."

"It was part of the Kremlin's ongoing effort to destabilize Ukraine and demonstrates ever more clearly Russia's involvement in the ongoing conflict," White House press secretary Sarah Sanders said in a statement. "This was also a reckless and indiscriminate cyber-attack that will be met with international consequences."

The Russian government said it "categorically denied the accusations."

"We think they have no basis and no foundation, and this is nothing else but the continuation of the Russophobic campaign," Dmitry Peskov, a spokesman for President Vladimir Putin, told reporters.

Related: The hacks that left us exposed in 2017

The ransomware infected computers and locked down their hard drives. It would then demand a $300 ransom to be paid in bitcoin.

But even if victims paid, they didn't recover access to their files.

Britain's National Cyber Security Centre, which investigated the attack, said it demonstrated a "high level of planning, research and technical capability."

It said the ransomware was inserted into a legitimate a piece of software used by most of Ukraine's financial and government institutions.

Ahmad said the attack had disrupted organizations across Europe, costing them hundreds of millions of pounds.

Reckitt Benckiser (RBGLY), the British maker of Lysol, Mucinex and Clearasil, said the attack had a negative effect on its second quarter sales.

In September, FedEx attributed a $300 million loss to the attack. The company's subsidiary, TNT Express, was forced to suspend business.

Mondelez said shipment delays resulting from the attack caused its second quarter revenue to drop 2.7%.