The capital's gun law was among the strictest in the U.S.
Dick Anthony Heller, 66, an armed security guard, sued the city after it rejected his application to keep a handgun at his home a short distance from the Supreme Court.
"I'm thrilled I am now able to defend myself and my household in my home," Heller said shortly after the opinion was announced.
The U.S. Court of Appeals ruled in Heller's favor and struck down Washington's handgun ban, saying the Constitution guarantees Americans the right to own guns and that a total prohibition on handguns is not compatible with that right.
The issue caused a split within the Bush administration. Vice President Dick Cheney supported the appeals court ruling, but others in the administration feared it could lead to the undoing of other gun regulations, including a federal law restricting sales of machine guns. Other laws keep felons from buying guns and provide for an instant background check.
White House reaction was restrained. "We're pleased that the Supreme Court affirmed that the Second Amendment protects the right of Americans to keep and bear arms," White House spokesman Tony Fratto said.
Scalia said nothing in Thursday's ruling should "cast doubt on long-standing prohibitions on the possession of firearms by felons or the mentally ill, or laws forbidding the carrying of firearms in sensitive places such as schools and government buildings."
In a concluding paragraph to the his 64-page opinion, Scalia said the justices in the majority "are aware of the problem of handgun violence in this country" and believe the Constitution "leaves the District of Columbia a variety of tools for combating that problem, including some measures regulating handguns."
The law adopted by Washington's city council in 1976 bars residents from owning handguns unless they had one before the law took effect. Shotguns and rifles may be kept in homes, if they are registered, kept unloaded and either disassembled or equipped with trigger locks.
Opponents of the law have said it prevents residents from defending themselves. The Washington government says no one would be prosecuted for a gun law violation in cases of self-defense.
The last Supreme Court ruling on the topic came in 1939 in U.S. v. Miller, which involved a sawed-off shotgun. Constitutional scholars disagree over what that case means but agree it did not squarely answer the question of individual versus collective rights.
Forty-four state constitutions contain some form of gun rights, which are not affected by the court's consideration of Washington's restrictions.