Judge Joseph Bruzzese Jr was shot several times just after 08:00 local time (12:00 GMT) in Steubenville on Monday morning.
Sheriff Fred Abdalla told reporters the attacker and the judge exchanged about five shots each.
A court officer also fired several shots at the suspect.
The Jefferson County prosecutor identified the attacker as Nathaniel Richmond, but said they had not yet identified a motive.
Mr Richmond is the father of Ma’Lik Richmond, a high school football player whose rape conviction made national headlines in the 2012.
Prosecutor Jane Hanlin said there is no connection between Judge Bruzzese and that rape case.
Judge Bruzzese, who has been on the bench at the Jefferson County courthouse since 1998, was airlifted to hospital in Pittsburgh to undergo emergency surgery.
The Steubenville city manager says that the judge is out of surgery and “doing fine”.
Sheriff Abdalla said he had advised the 65-year-old judge several years ago to carry a firearm during his commute.