Costa Rica's Congress has passed a bill which will legalise the use of marijuana for medical purposes and allow its cultivation for industrial use.
The cultivation and sale of marijuana for recreational purposes, however, will remain banned.
President Carlos Alvarado is expected to sign it within days.
Supporters of the bill say it will boost the agricultural sector and provide employment opportunities.
Following Tuesday's vote, Costa Rica
will join a host of other Latin American countries where medical marijuana has been made legal.
Recreational use of marijuana remains prohibited in most of the region except Uruguay, which in 2013 became the first country in the world to legalise it.
's bill was not without controversy. President Alvarado vetoed an earlier version, arguing that limits needed to be placed on individual cultivation and consumption.
The amended bill has the backing of the president, who said it would be "of great benefit to Costa Rica
Patients who will benefit from easier access to medical marijuana took to Twitter to thank Zoila Rosa Volio, the lawmaker behind the bill, for pushing it through Congress.
One cancer patient posted a tearful video describing how medical marijuana had helped her regain her appetite and walk again.