A reluctant District of Columbia Council voted unanimously Tuesday to allow people to carry concealed handguns in the nation's capital for the first time in nearly 40 years.

The bill was crafted to comply with a court ruling that struck down the District's ban on carrying handguns outside the home.

Residents and visitors who want to carry a concealed handgun would have to show a specific reason that they need one, among other requirements, and District leaders are hoping that the law would withstand further court challenges. But the attorney who challenged the ban on carrying guns has said the legislation is too restrictive and does not comply with the court ruling.

Several city lawmakers said they would prefer to maintain a total ban on concealed weapons, making clear that they were only voting for the bill to comply with the court ruling. The District could still appeal the decision. Democratic Council Chairman Phil Mendelson cautioned, however, that there are no remaining jurisdictions in the United States with a total ban on concealed handguns.

"I don't believe in guns. I don't believe in carrying guns," said Councilmember Marion Barry, a Democrat and a former four-term mayor. "I think the public ought to understand that all of us here are doing something we really don't want to do."

The District would join a handful of states that require residents to show a reason why they need a concealed-carry permit. The bill was modeled after similar laws in Maryland, New Jersey and New York that have withstood court challenges.

The Supreme Court struck down the District's 32-year-old ban on handguns in 2008. Since then, the District has required gun owners to register their firearms every three years, complete a safety course and be fingerprinted and photographed, among other requirements.

Those seeking a concealed-carry permit would have to complete a more extensive safety course than what's required for gun owners. Non-residents would also be able to get licenses if they meet the same standards. Open carrying of firearms would remain illegal.

The city's police chief would decide whether people have a compelling reason to carry a concealed firearm. People who have received death threats or have been the victims of domestic violence are among those who could be granted permits.

There are 3,250 registered handguns in the District. Mendelson has said he expects "a few hundred" people to obtain concealed-carry permits.

The emergency legislation approved Tuesday would take effect for 90 days, giving the council time to hold hearings and approve permanent legislation. Although the court's ruling had been put on hold to allow the council to act, federal prosecutors in the District have not been pursuing cases of carrying a pistol in public since the decision was made public.

The bill requires the signature of Mayor Vincent Gray, who has said he plans to sign it.

"This bill ensures that we will be able to meet the requirements of the Constitution while maintaining the maximum amount of safeguards possible to protect our residents, visitors, workers and public-safety officers," Gray said in a written statement.