Judge Edmond E. Chang issued his ruling Monday in a lawsuit by the Illinois Association of Firearms Retailers and three Chicago residents.
Chang noted Chicago's ban not only covers federally licensed firearms dealers, but also gifts among family members, all in the name of reducing gun violence.
Chang said a fundamental duty of government is to protect its citizens. However, he said it's also obligated to protect fundamental rights named in the Constitution, including the right to keep and bear arms for self-defense.
The judge said Chicago's ordinance goes too far in outright banning legal buyers and dealers from engaging in lawful acquisitions and lawful sales of firearms.
The ruling does not go in effect immediately. The city will have the chance to appeal. There will also be time for the city to consider and enact other sales-and-transfer restrictions short of a complete ban.
The Associated Press contributed to this report.