The ruling centred on Washington DC's decision to ban private possession of handguns in 1976, while rifles or shotguns were ordered to be kept disassembled or locked.
Washington DC officials said the ban was essential to keep gun crime down in one of the nation's most violent cities.
However, the law was challenged by Dick Heller, a security guard in the city who brought a lawsuit in 2003 saying the decision violated his right to bear arms, as decided by the second amendment.
Heller had argued that as a security guard who carried a gun while working, he should be allowed to keep it in his home for self-defence.
The main issue for the justices was whether the amendment protects an
individual's right to own guns in all circumstances, or whether that right is
tied only to service in a state militia.
The 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.''
Justice Antonin Scalia, who wrote the ruling, said the constitution
does not permit "the absolute prohibition of handguns held and used for
self-defence in the home".
The Supreme Court's decision affirms a lower court's ruling - the US Court of Appeals for Washington - which had also ruled in the Heller's favour in striking down Washington's handgun ban.
John McCain, the Republican presidential hopeful, said on Thursday in a statement that he was "pleased" at the ruling and criticised his Democratic rival, Barack Obama, for earlier comments on gun ownership.
"Unlike the elitist view that believes Americans cling to guns out of bitterness, today's ruling recognises that gun ownership is a fundamental right - sacred, just as the right to free speech and assembly," he said.
Adrian Fenty, mayor of Washington DC, said he was "disappointed" by the ruling but said local authorities would respect the court's decision.
In a dissenting opinion, Justice John Paul Stevens wrote that the majority ruling "would have us believe that over 200 years ago, the framers [writers of the US constitution] made a choice to limit the tools available to elected officials wishing to regulate civilian uses of weapons".
He said such evidence "is nowhere to be found".
Also dissenting, Justice Stephen Breyer wrote: "The decision threatens to throw into doubt the constitutionality of gun laws throughout the United States".
Ilya Shapiro, a constitutional analyst at the Cato Institute, a libertarian think-tank, told Al Jazeera the move would help make the US safer as it would enable people to defend themselves against criminals.
However, Juliet Leftwich, an expert on gun violence prevention at San Francisco's Legal Community Against Violence, said that argument was a myth.
"Numerous studies have shown that a gun in the home is much more likely to be used in a suicide or an accidental shooting or a homicide. They are actually more likely to be used against a family member."
"More guns do not make us safer."
The ruling comes one day after a worker at a plastics plant in the southern state of Kentucky used a handgun to shoot and kill five people inside the factory before killing himself in the latest in a series of deadly shooting sprees across the country.
The United States is estimated to have the world's highest civilian gun ownership rate.
In 2005 there were 30,694 gun deaths in the US, including 12,352 homicides and 17,002 suicides, according to data from the CDC National Centre for Injury Prevention.