Because of an administrative mix-up, a man charged with drug offenses was mistakenly released from the Dukes County jail this week but arrested less than 24 hours later when an Oak Bluffs police officer spotted him headed to the mainland on the ferry, authorities said.

Jason R. Willoughby, 26, of Edgartown, was arraigned on drug charges in Edgartown district court on Thursday, where bail was set at $250. But because the arrest put Mr. Willoughby in violation of his probation for a 2010 drug charge, clerk magistrate Liza Williamson also issued an order that he be held without bail until his next court appearance.

Instead, Mr. Willoughby was released because of an “administrative error” at about 5:30 p.m. Thursday after posting bail. “We should not have released him,” said Sheriff Michael A. McCormack. “Somebody should have picked it up.”

As luck would have it, Oak Bluffs police officer Jeffrey Trudel spotted Mr. Willoughby on Friday, and made phone calls that determined a default warrant for his arrest had been issued, McCormack and Oak Bluffs police said.

By coincidence, Mr. Trudel and a black Labrador named Buster are partners in the new K-9 drug unit in Oak Bluffs. Mr. Trudel was headed to the mainland for a training session, an Oak Bluffs police spokesman said.

Mr. Willoughby was arrested either on the ferry or in Woods Hole, and will be returned to the Island, the sheriff said.

He said the jail processes more than 1,000 people per year, and occasionally an error occurs, but luckily Mr. Willoughby was caught before he got out of reach. “He’s in custody,” he said. “That’s the good news.”

Last February, Mr. Willoughby was given a suspended sentence and placed on two years probation after pleading guilty to a distribution of a class E drug (Xanax) charge stemming from a July 2010 Oak Bluffs case.

This week, Edgartown police and the Martha’s Vineyard Drug Task Force officers served a search warrant at the Edgartown house where they said Mr. Willoughby was living. Off his room, police said, they found a grow room with marijuana plants and plastic bags containing what appeared to be marijuana. In a second room, another man had a safe in which what appeared to be marijuana was found.

Both men were arrested. Mr. Willoughby faces charges of distributing a Class D drug, possession of a class D drug to distribute and drug violation near a school or park. The house is within 1,000 feet of a preschool, according to documents filed with the court.