Vietnam agreed Wednesday to rescue more than 1 000 bears from illegal farms across the country, in a move to end the traditional medicine trade in the creatures’ bile.

Though bile farms are already outlawed in Vietnam, bears are still captured and caged in illicit facilities where their bile is extracted using invasive and painful techniques.

Vietnam’s Administration of Forestry (VNFOREST) and non-profit group Animals Asia signed an agreement Wednesday to rescue all remaining bears from farms, committing to end bile trade and close all facilities within five years.

“This is a truly historic day,” Animals Asia CEO Jill Robinson at the signing in Hanoi, adding that the decision “will lead to the definitive end to bear bile farming here in Vietnam”.

Bear bile farming has been outlawed in Vietnam since 1992. But many bile farms use a legal loophole allowing them to raise the animals as pets.

There are about 1 200 bears in captivity in Vietnam today, down from more than 4 000 in 2005, caged in more than 400 bear farms across the country.

Animals Asia estimates it will cost up to $20 million to rescue and build enough sanctuaries to house the bears, and called on donors, companies and the government to pitch in.

“We cannot do this by ourselves, the government needs to take responsibility for the wildlife in the country,” said Tuan Bendixsen, Vietnam director for Animals Asia.

Officials said funding is the main hurdle to rescuing the bears and putting an end to the trade.

“We face difficulties finding funds to prevent and stop the hunting and rescue of wild animals,” VNFOREST deputy director Cao Chi Cong said.

Bendixsen warned that bile farms could move into neighbouring Laos or Cambodia, and urged countries to adhere to an international convention that bans cross-border bear and bile trading.

Wednesday’s agreement follows an announcement in 2015 from Vietnam’s Traditional Medicine Association to remove bear bile from its list of sanctioned prescriptions by 2020.

The bears are often kept in small cages, and their bile is ‘free dripped’ via a hole in the animal’s gall bladder or a catheter. Many are starved, dehydrated, wounded and psychologically scarred when they are rescued.

Bear bile contains an acid which can help treat liver and gall bladder illnesses, though effective herbal alternatives are available.