The drugs trade has caused havoc and bloodshed in Latin America, from Colombia, the world's main source of cocaine, to Brazil, where rival trafficking gangs control many slums.
"God will call you to account for your deeds. Human dignity cannot be trampled upon in this way," Benedict said.
Thousands of followers sang and waved flags as the pontiff, flanked by bodyguards, then walked through the crowd, smiling and shaking hands.
About one-in-four of the 6,000 people who heard Benedict's address on a sports field at the farm were from various rehabilitation centres in Brazil.
"There are times when abortion is a sensible solution to a problem"
Bill Lewis, New Orleans, US
Send us your views
Patients and former addicts went up on the stage to tell their stories.
Ricardo Correa Ribeirinha, 31, said he was a former street child whose mother was a prostitute.
As a teenager, Ribeirinha sniffed glue, took cocaine and crack and was shot twice, but he now runs a government anti-drugs programme and is finishing college.
He said: "Many people thought I'd end up in jail or in a cemetery but I started to walk on the correct path of life that led me to God."
Hug from pope
Sylvia Hartwich, a 20-year-old from Berlin, wept as she described how she had tried to commit suicide several times.
Now she is a volunteer for a German branch of the programme.
"Now I'm a light for other girls. They receive strength from me to become women," she said.
Pope Benedict XVI hugs children at the drug rehabilitation centre [AFP]
Benedict hugged her as she left the stage.
Founded by Franciscan friars 25 years ago, the Farm of Hope helps rehabilitate addicts from as far away as Russia and the Philippines.
This year-long programme helps addicts kick the habit by making them work as farm hands and reading the Bible.
Throughout his trip to the word's most populous Roman Catholic country, Benedict has railed against the hedonism of modern society and exhorted people to lead more moral lives.
He has spoken out against sex outside of marriage, and reiterated the church's unflinching opposition to abortion.
He is also trying to rebuild the church's waning influence in Latin America, home to nearly half the world's 1.1bn Catholics.
"God will call you to account for your deeds. Human dignity cannot be trampled upon in this way"
Pope Benedict XVI
Benedict is also trying to stem the tide of people turning to Protestant groups or giving up on religion altogether.
On Sunday, he will address a conference of Latin American and Caribbean bishops in Aparecida, the site of Brazil's holiest shrine and largest cathedral visited by millions of pilgrims each year.
He also will celebrate an open air mass with hundreds of thousands of people at the Basilica of Our Lady of Aparecida, Brazil's national saint.