Johnson had been held since April 24 when he was stopped by Trooper First Class Jeff Kissner on Interstate 81 near the Salem Avenue exit.
McDowell said he found that Kissner's testimony wasn't credible.
"I listened to the tape of the preliminary hearing and I heard the testimony in the suppression hearing and there were discrepancies," McDowell said.
"Profile" traffic stops are illegal in Maryland. They are defined as traffic stops based on the type of vehicle, whether it has out-of-state plates, the appearance of the driver and occupants, their race and other factors.
Initial police reports in the case cited the reason for the traffic stop as following too close, according to court records.
Assistant State's Attorney Andrew Kramer said he has 15 days to decide whether he will appeal the ruling to the Maryland Court of Special Appeals.
Without the cocaine as evidence, the state would be unable to prosecute the case.
Despite the ruling, the cocaine will not be returned to Johnson, Kramer said.
At a bond hearing last April, Assistant State's Attorney Duane Gigeous said Johnson told police he went to New York with $30,000, bought the cocaine and was on his way back to North Carolina to sell the drugs.
Johnson's prior criminal record includes a 1987 conviction for robbery in New York, Gigeous said. Johnson was 13 at the time and charged as an adult, Gigeous said.
Johnson also has been convicted of drug, weapons and assault with intent to maim charges in New York, Gigeous said.
In North Carolina, Johnson was convicted in 1994 of conspiracy to traffic cocaine, Gigeous said.