The justices struck down the ban in a 5-4 decision, with Justice Antonin Scalia writing the opinion for the majority.

Washington Mayor Adrian Fenty said he was disappointed in the ruling but will give the district's police department 21 days to implement a process for registering handguns. It still will be illegal to carry handguns outside the home, and all pistols must be registered with police.

Officials said a hot line would be set up to handle questions about the new regulations.

The National Rifle Association said the high court had given it the ammunition to challenge other cities' gun-control measures.

At issue in District of Columbia v. Heller was whether Washington's ban violated the right to "keep and bear arms" by preventing individuals -- as opposed to state militias -- from having guns in their homes.

"Undoubtedly some think that the Second Amendment is outmoded in a society where our standing army is the pride of our nation, where well-trained police forces provide personal security and where gun violence is a serious problem," Scalia wrote. "That is perhaps debatable, but what is not debatable is that it is not the role of this court to pronounce the Second Amendment extinct." More on Americans' relationship with firearms

Scalia was joined by Chief Justice John Roberts and Justices Samuel Alito and Clarence Thomas, all of whom are considered conservative voices on the court. Justice Anthony Kennedy, often seen as a swing vote, also joined the majority.

Justices John Paul Stevens and Stephen Breyer delivered dissenting opinions and were joined by their liberal counterparts Ruth Bader Ginsburg and David Souter.

District of Columbia officials argued they had the responsibility to impose "reasonable" weapons restrictions to reduce violent crime, but several Washingtonians challenged the 32-year-old law. Some said they had been constant victims of crimes and needed guns for protection. Hear the arguments presented to the high court »

Scalia wrote that the majority was sympathetic to Washington's problems with guns and crime but banning handguns was not a solution.

"The Constitution leaves the District of Columbia a variety of tools for combating that problem, including some measures regulating handguns," Scalia wrote. "But the enshrinement of constitutional rights necessarily takes certain policy choices off the table. These include the absolute prohibition of handguns held and used for self-defense in the home." Watch a gun shop owner's reaction »

Breyer, however, argued in his dissent that the framers of the Constitution did not present self-defense as their main reason for the Second Amendment.

"The self-defense interest in maintaining loaded handguns in the home to shoot intruders is not the primary interest, but at most a subsidiary interest," he wrote. "The Second Amendment's language, while speaking of a 'militia,' says nothing of 'self-defense.' "

Washington residents can protect themselves from crime though other means, Breyer wrote: "The law concerns one class of weapons, handguns, leaving residents free to possess shotguns and rifles, along with ammunition." iReport.com: What's your reaction to the ruling?

In March 2007, a federal appeals court overturned the city's ban, which keeps most private citizens from owning handguns and keeping them in their homes.

It was the first time a federal appeals court ruled a gun law unconstitutional on Second Amendment grounds.

City attorneys urged the high court to intervene, warning, "The District of Columbia -- a densely populated urban locality where the violence caused by handguns is well-documented -- will be unable to enforce a law that its elected officials have sensibly concluded saves lives."

There were 143 gun-related murders in Washington last year, compared with 135 in 1976, when the handgun ban was enacted.

The Second Amendment says, "A well-regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed."

The wording repeatedly has raised the question of whether gun ownership is an individual right, or a collective one pertaining to state militias and therefore subject to regulation.

In an Opinion Research Corp. poll of 1,035 adult Americans this month, 67 percent of those surveyed said they felt that the Second Amendment gave individuals the right to own guns. Thirty percent said it provided citizens the right to form a militia. The poll had a margin of error of plus or minus 3 percentage points. See poll results »

The Supreme Court had avoided the question since the Bill of Rights was ratified in 1791. The high court last examined the issue in 1939 but stayed away from the broad constitutional question.

Breyer expressed concern in his dissent that the majority's ruling could jeopardize the "constitutionality of gun laws throughout the nation."

He added, "I can find no sound legal basis for launching the courts on so formidable and potentially dangerous a mission."

Only Chicago, Illinois, has a handgun ban as sweeping as Washington's, though Maryland, Massachusetts and San Francisco, California, joined the Windy City in issuing briefs supporting the district's ban.

The NRA, Disabled Veterans for Self-Defense and the transgender group Pink Pistols -- along with 31 states -- filed briefs supporting the District of Columbia's gun owners.

In a statement, President Bush also praised the decision, saying he agreed with the court's interpretation of the Constitution.

"As a longstanding advocate of the rights of gun owners in America, I applaud the Supreme Court's historic decision today confirming what has always been clear in the Constitution: the Second Amendment protects an individual right to keep and bear firearms," Bush said.

"I also agree with the Supreme Court's conclusion that the D.C. firearm laws violate this fundamental constitutional right. The District of Columbia should now swiftly move to ensure that its residents' rights under the Second Amendment are fully protected," he said.

In January, Bush signed the first major gun-control legislation in 14 years, strengthening background checks on gun buyers. Political momentum for the bill increased after the Virginia Tech shootings last year, when a student shot and killed 32 people and then himself.