Peru's congress late Thursday overwhelmingly approved a measure supported by President Pedro Pablo Kuczynski that legalises marijuana for medicinal use.
The proposal at first was controversial because of the thriving illegal drug trade: Peru is the world's second largest producer of coca leaves - the source plant for cocaine - and some worried that drug gangs would branch into the marijuana business.
Proponents emphasised however that the measure is aimed at extracting components from marijuana to address specific ailments.
The Kuczynski administration proposed legalising medicinal marijuana in February, after police busted a home lab and arrested a group of parents who were distilling cannabis oil for children ill with cancer and severe cases of epilepsy.
The head of Peru's single chamber congress, Luis Galarreta, wrote on Twitter just before midnight that lawmakers voted mindful of "those people who need it for their treatment."
Pro-government lawmaker Alberto de Belaunde said that all charges should be dropped against the parents.
"Science is on our side, the regional current is on our side. Let's not let our fears paralyse us," he said ahead of the vote.
In 2013 Uruguay became the first country in the world to legalise pot from production to sale. The drug is sold only to people who have officially registered with a licensed pharmacy, and with a monthly limit of 40 grams.
Mexico, Colombia, Chile and Argentina have since authorised the cultivation and consumption of marijuana for medicinal and scientific purposes.