The anti-gun campaign lost supporters in the last few weeks

Sixty-four percent of those who voted rejected the proposed ban, which was backed by the government, the Catholic Church and the United Nations.

The gun ownership lobby successfully argued that guns were needed for personal security.

Guns kill one person in Brazil every 15 minutes, giving it the world's highest death toll from firearms.

Last year, there were 36,000 shooting deaths. The UN says guns are the biggest cause of death among young people in Brazil.

The immediate consequence of the referendum is that gun shops will remain open.

Individual rights

The BBC's Steve Kingstone in Sao Paulo says that the result may surprise outsiders, given the horrific scale of gun violence in Brazil.

The defeated "Yes" campaign had enjoyed an early lead in the opinion polls, but it was quickly outmanoeuvred.

The "No" campaign convinced voters that the proposed ban would have no effect on criminals, on the grounds that criminals do not buy guns legally in shops.

AGAINST THE BAN If I had the money, I would have a weapon to try to protect myself and my family... The police are never going to arrive in time

Maria

Shantytown resident

Gun crime blights Rio slums

Beni Barbosa, the "No" campaign spokesman, said: "We managed to get our message across that Brazilians have individual rights which the state cannot take away."

"Here, people were not choosing whether to have a gun or not. They were voting for their rights to choose."

Anti-gun campaigners said the swing away from a "Yes" vote was the result of people's desire to protest against the government's security policy.

"We didn't lose because Brazilians like guns. We lost because people don't have confidence in the government or the police," said Denis Mizne, of anti-violence group Sou da Paz.

"The 'No' campaign was much more effective. They are talking about a right to have a gun - it is a totally American debate."

Anti-gun campaigners also accused gun makers and lobby groups such as the US National Rifle Association (NRA) of manipulating people's fears.

Millions of guns

The referendum has been watched closely by other countries where gun-ownership is under debate.

In Washington, an NRA spokesman called the result "a victory for freedom".

Some opposition came from favelas, often the scene of turf wars

The referendum rounded off a series of campaigns run by the government of President Luiz Inacio Lula da Silva to cut down on gun crime.

Penalties for unlawfully carrying a gun have been increased, and money has been offered to people who surrender their weapons in amnesties.

The proposal to ban firearms initially had strong public support.

But opinion polls in recent days showed this backing had weakened dramatically as campaigns against the ban got off the ground.

Some opposition to the ban also came from shanty towns, or favelas, the scene of vicious turf wars between drug gangs.

Maria, a shantytown resident whose sister was gunned down by an ex-boyfriend, said disarmament would make little difference.

"If I had the money, I would have a weapon to try to protect myself and my family," she told the BBC. "The police are never going to arrive in time and if they do, they may kill you."

There are estimated to be more than 17 million guns in Brazil, nine million of which are not registered, according to a survey by non-governmental groups.