The US Congress has approved the first major gun legislation since 1994, improving background checks on buyers.
The bill will improve state reporting on people barred from buying guns
The bill was prompted by the deaths of 32 people at Virginia Tech University in April, when a mentally ill student used two guns he had been able to buy.
The law clarifies what mental health records must be included in checks and gives funds to states to help automate the processing of records.
It has been widely welcomed but critics say it will do "more harm than good".
The shooting rampage by student Cho Seung-hui on the campus at Virginia Tech in April shocked Americans.
That shock was all the greater when it emerged that a judge had ruled that Cho was a danger to himself and should receive mental health treatment.
Cho Seung-hui should have been barred from buying weapons
But because of concerns over privacy laws, the judge's report never made it into federal records.
This meant Cho was able legally to buy the guns he used to kill 32 people and himself.
"A credible...federal database to provide accurate background checks benefits everyone," said Sen Patrick Leahy, a co-sponsor of the bill.
Under existing legislation from 1968, people barred from buying guns include those convicted of a crime punishable by more than a year in prison, drug addicts and those found by a court to be mentally disabled.
But privacy laws and budget restraints have meant most states fail to pass on such information to the National Instant Criminal Background Check System (NICS), the main way gun dealers determined whether potential buyers are legally able to purchase a gun.
The new legislation aims to close those gaps:
- it provides funds to improve NICS
- sets out which mental health records should be reported
- provides $375m (£187m) a year for five years for states and state courts to improve processing of mental health information
- states failing to comply could lose federal funds
- states with good records could receive financial incentives
The bill also provides funds to allow people who have "overcome a disqualifying mental illness or disability" to petition for the restoration of their right to own a gun.
The legislation has been welcomed by the powerful National Rifle Association gun lobby, which said that it did not impose new restrictions on gun ownership but improved compliance with the existing rules.
"This would ensure that purely medical records are never used in NICS. Gun ownership rights would only be lost as a result of a finding that the person is a danger to themselves or others, or lacks the capacity to manage his own affairs," an NRA statement said.
A gun control group, the Brady Campaign to Prevent Gun Violence, also urged President George W Bush to sign the bill into law.
"Every day that passes until this legislation becomes law, dangerous people will go into gun stores and not be blocked from buying deadly weapons, thus putting lives at risk," the group said.
But another campaign group, the Violence Policy Center, said the legislation had been "hijacked by the gun lobby and would now do far more harm than good".
"Rather than focusing on improving the current laws prohibiting people with certain mental health disabilities from buying guns, the bill is now nothing more than a gun lobby wish list," the VPC said.
The legislation would waste money to restore the gun privileges of people previously determined to present a danger to themselves or others, the group said.
It is estimated that there are some 250m privately-owned guns in the US, which has a population of 300m.