Brazilian officials see street protests and resurgent criminal violence in some of Rio's slums as top security concerns, with the World Cup set to kick off six months from now.
This Latin American powerhouse is pulling out all the stops to ensure security for the hundreds of thousands of visitors expected for the planet's most-watched sporting event, the first to be held in Brazil since 1950.
Advertisement"You can protest over causes which you see as just ... but remember that we are staging an event that is very crucial for our country. So treat visitors well," Ricardo Trade, head of the World Cup's Local Organizaing Commitee, said recently.
Brazil is used to organizing mammoth events such as the Rio carnival or Pope Francis' visit, which drew three million pilgrims on Copacabana beach in July.
But it remains one of the world's most violent countries, with a murder rate of 27 per 100,000 inhabitants.
Last year, a strategic plan worked out with FIFA, football's world governing body, spelled out the key areas to protect, coordination between public and private security firms and assessed the main threats from organized crime, terrorist attacks and football hooliganism.
It was activated for the Confederations Cup, a dry run for next year's Wold Cup, in June.
But authorities had not anticipated June's social unrest when more than one million Brazilians took to the streets nationwide to demand more spending on public transport, health and education.
The demonstrators also railed against the high cost of staging the World Cup and the 2016 Rio Summer Olympics.
The protests have since petered out but have occasionally turned more violent as "black bloc" anarchists went on the rampage in major cities such as Rio and Sao Paulo.
But authorities are bracing for a possible resumption of social turmoil during the World Cup -- scheduled from June 12 to July 13 -- and during the national elections in October when President Dilma Rousseff will seek re-election.
"There will be demonstrations," said a government official. "The question is: How big will they be ?"
In late October, the government announced it was setting up an intelligence task force to thwart and control possible violence during demonstrations.
Authorities also moved to upgrade the police's crowd control capabilities. French riot police officers were sent to Rio to share their know-how with their Brazilian colleagues.
Another source of concern is a resurgence of criminal violence in some of Rio's hilltop shantytowns, where beginning in 2008, police restored control by evicting the drug gangs that had held sway for decades.
To date, 36 so-called police pacification units (UPPs) have been deployed in more than 180 of the city's 750 favelas. By next year 12,500 police officers will be mobilised in 40 such units.
The muscular "pacification" drive led to a 40 percent drop in the murder rate but the police officers -- some of whom are violent and corrupt -- deployed in these underprivileged communities are not always welcome.
Over the past months, there has been an increase in robberies and night shootouts as well as the reappearance of heavily armed drug traffickers in these "pacified" favelas.
And in recent days, a new phenomenon appeared with roving gangs of rowdy youths pouncing on Rio beachgoers and perpetrating mass robberies in broad daylight.
Police immediately beefed up beach security and the US consulate in Rio issued a travel advisory warning its nationals of "increased incidents of crime in areas frequented by tourists."
Meanwhile, a top drug trafficker jailed in Rio recently told police about alleged plans by "Red Command", the city's top crime syndicate, to regain control of pacified slums.
He notably pointed to renewed contacts between the Red Command and Sao Paulo's powerful PCC (First Capital Command) prison-based criminal gang.
So authorities are not taking any chances and have said they will deploy twice the number of security personnel (54,734) used during the Confederations Cup.
Some units have been trained by agents from the US Federal Bureau of Investigation (FBI) to respond to any external threats.
"Brazil is not targeted by terrorists," said Michel Misse, an expert on violence at Rio de Janeiro Federal University.
But officials have vowed to remain vigilant.