Under the law -- inspired by U.S. initiatives in Colorado and Washington state and approved by the Uruguayan Senate 16-13 late Tuesday -- the country will create a state-run Institute for the Regulation and Control of Cannabis to oversee the planting, harvesting and sale of marijuana by private companies and residents 18 or older.
Households will be allowed to grow up to six plants each and harvest up to 480 grams, or a little more than 1 pound, of pot a year. Cooperatives, known as "growers clubs," may grow up to 99 plants together, Uruguayan newspaper La Republica said.
Residents may also buy up to 40 grams of marijuana at $1 a gram from licensed pharmacies a month, the equivalent of about 60 cigarettes.
The law is intended to cut out drug traffickers from the lucrative business, put the trade into state hands, and reduce the violence and social ills connected to illegal trafficking.
Opponents say the measure will open the way for greater drug use. Some senators argued during more than 12 hours of debate Tuesday the legislation was unconstitutional.
The measure follows skepticism among Uruguayan leaders of U.S.-backed drug-prohibition strategies that have sparked armed conflicts.
"The repressive way" in fighting drug trafficking "is failing," Mujica said in signaling he would sign the measure that would make Uruguay the first country to legalize marijuana.
The new law, taking a new tack on the war on drugs in Latin America, requires "a little courage and a little daring," Mujica said, but it will help the country explore "new paths," Uruguay's El Pais reported.
Other Latin American leaders advocating marijuana legalization include Guatemalan President Otto Perez Molina and Colombian President Juan Manuel Santos.
Lawmakers in Mexico, Puerto Rico, Chile, Belize, Barbados, and Trinidad and Tobago are considering drafts of bills that would legalize pot, the Wall Street Journal said.
The law was inspired in part by Colorado and Washington, which became the first U.S. states to legalize the sale and possession of cannabis for recreational use following voter approval in November 2012 of marijuana reform laws.
"We know the Colorado and Washington initiatives and they've had a big impact on our thinking," Sebastian Sabini, the Uruguayan legislator who sponsored the House law, told the Journal.
Uruguay under Mujica has become one of Latin America's most progressive nations. Since he was elected in 2009, his country legalized gay marriage and abortion, and banned outdoor ads for cigarettes.