Representative John Conyers Jr. of Michigan narrowly escaped a political fiasco on Friday when a federal judge granted him a place on the Democratic primary ballot in August, allowing him to survive a campaign misstep that left him hundreds of valid signatures short on his petitions for re-election.

Mr. Conyers, a Detroit Democrat who was first elected in 1964, had found his re-election prospects at risk when his campaign failed to collect the required 1,000 valid signatures. At least two workers collecting them were not properly registered to vote, another violation of state law. What initially appeared to be a minor mistake quickly became a grievous error that threatened the career of one of the most senior members of Congress, who is a founder of the Congressional Black Caucus and the ranking Democrat on the House Judiciary Committee.

In his ruling on Friday, Judge Matthew F. Leitman of Federal District Court said that the “failure to comply with the registration statute was the result of good-faith mistakes.”

“They believed they were in compliance with the statute,” the judge wrote.

Judge Leitman added that the First Amendment rights of Mr. Conyers and the signature collectors working for his campaign were “severely burdened” under the current law.