The National Rifle Association sued the city of San Francisco on Friday to overturn its handgun ban in public housing, a day after the U.S. Supreme Court struck down a handgun ban in the nation's capital.

The legal action follows a similar lawsuit against the city of Chicago over its handgun ban, filed within hours of Thursday's high court ruling.

In San Francisco, the NRA was joined by the Washington state-based Citizens Committee for the Right to Keep and Bear Arms and a gun owner who lives in the city's Valencia Gardens housing project as plaintiffs.

The gun owner, who is gay, says he keeps the weapon to defend himself from "sexual orientation hate crimes." He was not identified in the complaint because he said he fears retaliation.

San Francisco Mayor Gavin Newsom said the city will "vigorously fight the NRA" and defended the city's ban as good for public safety.

"Is there anyone out there who really believes that we need more guns in public housing?" Newsom said. "I can't for the life of me sit back and roll over on this. We will absolutely defend the rights of the housing authority."

San Francisco City Attorney Dennis Herrera said the Supreme Court ruling didn't address gun bans on government property and that he was "confident that our local gun control measures are on sound legal footing and will survive legal challenges."

San Francisco also requires residents to keep guns in lockboxes or equip them with triggerlocks. That law, passed by the county supervisors last year, wasn't challenged in Friday's lawsuit.

A state appeals court has overturned a broader citywide gun ban passed by voters in 2005.

The Chicago lawsuit challenges its 1982 ordinance that makes it illegal to possess or sell handguns in the city.

NRA lawyer C.D. Michel said both lawsuits were necessary to expand the Supreme Court's ruling beyond Washington, a federal district, to states and cities.

"The Supreme Court decisions was very encouraging," Michel said. "But it is just a start."