JI-PARANÁ, Brazil — As the night sky enveloped this outpost in Brazil’s Amazon basin, the ceremony at the open-air temple began simply enough.

Dozens of adults and children, all clad in white, stood in a line. A holy man handed each a cup of ayahuasca, a muddy-looking hallucinogenic brew. They gulped it down; some vomited. Hymns were sung. More ayahuasca was consumed. By midnight, the congregants seemed strangely energized. Then the dancing began.

Such rituals are a fixture across the Amazon, where ayahuasca has been consumed for centuries and entire religions have coalesced around the psychedelic concoction. But the ceremony one night this month was different: Among those imbibing from the holy man’s decanter were prison inmates, convicted of crimes such as murder, kidnapping and rape.

“I’m finally realizing I was on the wrong path in this life,” said Celmiro de Almeida, 36, who is serving a sentence for homicide at a prison four hours away on a road that winds through the jungle. “Each experience helps me communicate with my victim to beg for forgiveness,” said Mr. de Almeida, who has taken ayahuasca nearly 20 times at the sanctuary here.