D.C. police were told Sunday not to arrest people for carrying handguns on the street in the wake of a judge’s ruling that overturned the city’s principal gun-control law.

However, the D.C. attorney general’s office said it would seek a stay of the ruling while the city decides whether to appeal.

In an order approved by Police Chief Cathy L. Lanier, police were told that District residents are permitted to carry pistols if the weapons are registered. Those who had not registered their handguns could be charged on that ground, the instruction said.

The number of registered pistols is thought to be low.

Lanier’s instructions to police also said that residents of other jurisdictions without felony records would not be charged under the ban on carrying pistols.

Meanwhile, Ted Gest, the spokesman for the D.C. attorney general’s office, which defended the handgun ban in court, said it will “be seeking a stay shortly,” so the order by U.S. District Judge Frederick J. Scullin Jr. may not be in effect for long.

“Its time of effectiveness could be very short,” Gest said.

Legal experts have said that in many cases all parties in a lawsuit are given the opportunity to appeal a ruling before it takes effect. However, it was decided at some point Sunday that Scullin’s ruling took immediate effect, and that set off efforts to bring the city into compliance.

Scullin, a senior U.S. District Court judge who normally sits in the Northern District of New York, wrote in his ruling that he was stopping enforcement of the law “unless and until” the city adopted a constitutionally valid licensing mechanism.

“The decision is in effect, unless and until the court stays its decision,” said Alan Gura, the lawyer who represents the group challenging the ban.

“This is now a decision that the city is required to follow — the idea that the city can prohibit absolutely the exercise of a constitutional right for all people at all times, that was struck down. That’s just not going to fly.”

It appeared late Sunday that the city was acting in conformity with Gura’s position that registered handguns could be carried in public. The instruction issued to officers said that “until further notice” they “shall not enforce” the law that prohibited the carrying of handguns.

Gura said that allowing people to carry handguns for self-defense will cut crime.

“This is a fantastic improvement in public safety,” he said.

A statement from the office of Mayor Vincent C. Gray (D) said he “remains committed to having reasonable gun safety measures in the District and will work with the [Office of the Attorney General and D.C. police to ensure that our gun laws remain strong.”

D.C. Council member Muriel Bowser, the Democratic nominee to replace Gray, said she had encouraged Attorney General Irvin B. Nathan to appeal. A member of the council’s committee on the judiciary and public safety, Bowser (D-Ward 4) said she planned to work on “any legislative action needed to protect our gun laws.”

The decision “is troubling and threatens public safety” in the city, she said.

Council member David A. Catania, who is running for mayor as an independent, did not respond to a request for comment.

Another council member, Mary M. Cheh (D-Ward 3), noted that the ruling was made at the trial court level and was issued by an out-of-state judge “sitting down here on a temporary status” and possibly lacking an appreciation of the District’s special circumstances.

“We’re just full of places where guns would be not only inappropriate but highly dangerous,” Cheh said.

Eleanor Holmes Norton (D), the District’s nonvoting delegate to Congress, said it was significant that the ruling did permit the city to regulate the carrying of handguns.

The ruling results from a case brought four years ago by Tom G. Palmer, the nonprofit Second Amendment Foundation and three others. Palmer is one of those who successfully sued the District in the Heller case that led to the landmark Supreme Court decision that said the Second Amendment provides an individual right to own handguns.

Many states regulate who can carry handguns in public through background checks and required gun-safety courses. But the District’s elected leaders in 2008 repealed the police chief’s authority to issue handgun-carry licenses, which Palmer and his attorney say violates the Second Amendment.

“By requiring a permit to carry a handgun in public, yet refusing to issue such permits . . . defendants maintain a complete ban on the carrying of handguns in public by almost all individuals,” the complaint first filed in 2009 said.

On Sunday, Palmer characterized the two cases in which he has been a plaintiff as dealing with the two parts of the constitutional phrase “to keep and bear arms.” After the Heller decision, he said, the District allowed residents to keep guns, but not to bear them.

“The District government simply refused to follow the law, and that was what occasioned this second lawsuit,” Palmer said. “They steadfastly refused to recognize the full text of the Second Amendment, which says ‘keep and bear.’ ”

The Supreme Court’s 5-to-4 Heller decision made clear that the Constitution guarantees an individual right to gun ownership within the home. But it did not deal with whether the right extended to public places.

Courts have been wrestling with that question ever since. In December 2012, a federal court of appeals struck down a similar outright ban on carrying loaded guns in public in Illinois, which was the last state to impose such a prohibition.

Justice Antonin Scalia, who wrote for the majority in the Heller case, recognized the power of governments to limit the carrying of firearms in sensitive places such as schools and government buildings.

In response to the Heller decision, the District passed a new law that allows residents with valid registrations to keep a firearm in their homes. The law expressly got rid of the carry provision because of the District’s “unique character” as home to the federal government, high-profile officials, iconic memorials, diplomats and thousands of large public events.

Chief Lanier has testified at a congressional hearing that the city is “filled with ‘sensitive places.’ Our laws should reflect that reality.”

“Protecting government officials and infrastructure is a challenge in every city,” but greater in the District, the city’s attorney general said in a court filing, defending the handgun ban.

Allowing people to carry handguns on the streets of Washington would make it “far more difficult” for police to ensure safety and security, the lawyers said.

Federal courts have generally upheld restrictions on who can carry guns in public places. Last year, the U.S. Court of Appeals for the 4th Circuit upheld Maryland’s tough restrictions on gun licensing. Maryland’s law allows law enforcement officials to decide whether a person may carry a gun and requires residents to provide a “good and substantial reason” for doing so.

Maryland’s approach is similar to permitting systems in California, New Jersey and New York. The appeals court cited its agreement with a decision by the 2nd Circuit upholding New York’s licensing system that requires a person to demonstrate “proper cause” before a permit is issued.

The D.C. case was brought by the same attorney, Gura, who argued the Heller case.

Gura said he hoped the ruling would not prompt another city effort to bolster gun laws.

“They really should just come to terms with the constitutional requirement and stop resisting the right to bear arms.”

Martin Weil, Peter Hermann and Clarence Williams contributed to this report.