Russia signed an agreement Monday with a group of international scientists to free nearly 100 whales that have been held for months in cramped pens in Russia's Far East.

Images of the whales, kept in cramped enclosures in a bay near the Sea of Japan port town of Nakhodka, first appeared last year, triggering a wave of criticism.

The animals were originally caught by a company which planned to sell them to China. But once their fate became known, the Kremlin intervened and ordered local authorities to act to find a way of freeing the animals.

Although the Kremlin agreed that the 11 orcas and 87 beluga were held in cruel conditions, it said it was difficult to release them into the wild without harming them.

On Monday, however, international scientists, including Jean-Michel Cousteau, son of French marine expert Jacques Cousteau, signed a joint agreement with Russian scientists, backed by the local authorities, to free the mammals. Their release is likely to be phased.

"A decision in principle has been taken to release all the animals into the wild," Oleg Kozhemyako, the governor of Primorsky region, told reporters after the signing ceremony.

"Scientists from Cousteau's team and Russian scientists will decide when and which animals to release."

A special rehabilitation facility for whales would be set up under the agreement, with conditions as close as possible to their natural environment. Any whales in the Sea of Japan that were hurt or got into trouble could be treated there, said Kozhemyako.

The video below shows some of the whales being held in captivity:

Since November, beluga and orca whales have been kept in small pens not far from Vladivostok on Russia's Pacific Coast. 4:06

Cousteau told reporters it was a very emotional moment for him, and the scientists would do all they could to save the animals.

"I know it's a lot of work, but I have no doubt that we are going to succeed," said Cousteau.

The scientists promised they would devise a plan to release the whales, some of which were captured as long ago as July, by next month.

The Kremlin has said Russia has no direct ban on catching whales, but they can only legally be caught in specific circumstances, for scientific and educational purposes.

Russia's FSB security service brought charges against four companies involved in the case in February for breaking fishing laws.

Marine parks expanding in China

Russian environmental groups have been pushing the Putin government for years to stop the trade in ocean mammals. The four companies that captured these animals were issued legal permits to keep the whales for "educational" reasons. They then quickly turned around and cut deals with Chinese marine parks.

Orcas can sell for up to $5 million US each, according to several animal welfare groups that have investigated the practice. Greenpeace estimates a beluga can sell for up to $150,000 US.

Marine parks have been rapidly expanding in China, with more than 60 already operating and dozens more in the planning stages. The environmental group the China Cetacean Alliance claims 491 marine mammals have already been put into captivity in the country.

Statistics from the Convention on International Trade in Endangered Species (CITES) suggest as many as 13 orcas caught in Russian waters were sold to China between 2013 and 2016.

In Canada, a bill that would ban aquariums from having dolphins and whales in captivity, introduced in 2015, passed through a House of Commons committee last week and must now go for a final debate and vote. Critics, including the owners of Marineland in southern Ontario, have said the bill will hurt science and legitimate research programs.

The Vancouver Aquarium, which used to keep orcas and belugas for public performances, also initially strongly opposed the legislation. It has since phased out its captive cetacean program but continues to take in stranded and distressed whales and dolphins.