The lawsuit contends that Judge Ewing took away some of Mr. Willey’s poor clients and refused to appoint him new ones because “he sought to provide a vigorous legal and factual defense for his clients.”

Mr. Willey said he has been appointed to only one case before Judge Ewing since May 2016, and that appointment was effectively made by another judge. The lawsuit asks for him to be reinstated and for Judge Ewing to be barred from retaliating against him.

In an interview, Judge Ewing denied the allegations, saying he assigned some cases to another lawyer because many of Mr. Willey’s cases were unresolved and Mr. Willey seemed overwhelmed. He also said that, as far as he knows, Mr. Willey’s eligibility to represent indigent defendants has never changed.

But according to the lawsuit, Judge Ewing told Mr. Willey that he spent too much time defending individual clients.

“You are the only attorney” to routinely ask for a paid investigator, the judge said. He also complained that cases resulting in guilty pleas generally should not take more than three hours of work, but Mr. Willey sometimes took longer.

Relatively few criminal cases ever go to trial; most end instead in guilty pleas. But that does not mean that time and money is spent on them in vain. The length of the sentence offered in a plea bargain can hinge on the strength of the prosecution’s case, and a thorough evaluation of the evidence can put defense lawyers in a stronger negotiating position.

Mr. Willey’s lawsuit offered the example of a client charged with breaking into a car. The client faced up to a year in jail, but Mr. Willey found “blatant inconsistencies” in police statements. When prosecutors declined to reduce the charge, he hired an investigator, the lawsuit says.