Brazil's Senate has passed a bill to outlaw the carrying of guns in public and control illegal gun ownership.
Huge anti-gun protests were held in recent months
The law will tighten rules on gun permits and create a national firearms register, with strict penalties for owning an unregistered gun.
A referendum will be held in 2005 on whether to ban gun sales outright.
About 40,000 people are shot dead each year in Brazil, mainly in urban shanty towns, giving the country one of the worst murder rates in the world.
President Luiz Inacio Lula da Silva will now give the law final approval.
After the law takes effect, gun owners will have 180 days to register their weapons or surrender them to the police.
Thereafter, anyone with an unregistered gun faces a four-year prison term.
Only strictly defined groups of people - including police, security officials, target shooters and transport companies - will be able to obtain a gun licence.
The legal age for owning a gun is being raised from 21 to 25.
In October 2005, a national referendum will ask: "Should the sale of arms and munitions be prohibited in Brazil?"
More than 50 other gun control bills have come before Congress over the years and failed to be passed.
Brazil's arms industry is the world's sixth largest, and strong lobbying has in the past blocked any changes to the law.
Campaigners say that the difference this time is that public opinion is overwhelmingly in favour of gun control.
"The country is going to start to have efficient gun
controls, something it's not had up to today," said Antonio Rangel of Rio de Janeiro anti-violence group Viva Rio.
Over 100 police officers are shot dead in Sao Paulo alone, and thousands of civilians are killed in gun battles with police.