Supporters needed 36 votes to override, and they got 40. The bill now goes to the House.
It was inspired by a Wilmette man who shot a burglar and then was charged with breaking the local law against handguns. The bill says someone who shoots an intruder with an illegal gun can't be prosecuted for violating the ban.
The homeowner could still be charged with other crimes if prosecutors think the shooting was improper. Gov. Rod Blagojevich says the legislation might encourage people to defy local gun laws.
Supporters say the state should not interfere with people's right to protect their homes.