BALTIMORE — A Baltimore police officer charged with selling heroin must remain behind bars.

A federal judge on Friday ordered Daniel Redd, who has been indicted on drug and gun charges, detained pending trial. The ruling reverses a magistrate’s decision from a day earlier that permitted Redd to be released.

Redd is accused of making calls related to drug deals while on duty as a police officer. Court papers say that in March, he gave heroin to a co-defendant in the Northwest District Police Station parking lot while in uniform.

Prosecutors say that Redd admitted after his arrest that he had participated in three drug transactions.