ROCKLAND — A 24-year-old Massachusetts man arrested Wednesday on suspicion of dealing heroin and fentanyl has been linked to the overdose death of a St. George man the previous night.

District Court Judge Paul Mathews set bail Friday at $50,000 cash for Cameron Soto of Fairhaven, Massachusetts. Soto made his initial appearance Friday in Knox County Unified Court on a charge of Class A aggravated trafficking in heroin and Class C possession of a firearm by a prohibited person.

Soto and Trevor Teves, 18, were arrested Wednesday in the parking lot of Town Line market in Warren after Soto sold drugs in St. George to a confidential informant, according to an affidavit filed in court by the Maine Drug Enforcement Agency. Teves was charged with possession of a firearm by a prohibited person, according to the Maine Department of Public Safety. Teves has been released on $1,000 cash bail.

According to the affidavit, MDEA had been investigating Soto in connection with the distribution of heroin and fentanyl in Knox County.

Soto was released from the Maine State Prison in Warren on Dec. 30. He had been sentenced in September 2014 in Knox County to three years in prison for dealing crack cocaine in December 2013 in Rockland. Soto was arrested at the Trade Winds Motor Inn at that time after police responded to a fight that began when a local man confronted Soto for selling drugs to the man’s sister.

Soto also had a drug conviction in Massachusetts in 2012.

According to the affidavit, MDEA tried to make a controlled purchase of drugs from Soto on March 3, but the deal was compromised. Soto was later recorded in a phone call saying he had seen DEA agents in the lobby of the Hampton Inn in Thomaston, where he planned to make the transaction.

On Tuesday evening, the Knox County Sheriff’s Office responded to a residence on Ridge Road in St. George where 48-year-old Edward Rogers died after injecting heroin or fentanyl, according to the affidavit.

Police searched the victim’s cellphone and saw messages from a person whose contact name was “Pollie.” MDEA reported in the affidavit that Soto goes by the name “Paulie.”There was a message from “Pollie” on Rogers’ phone shortly after the time that emergency medical workers arrived.