RIO DE JANEIRO — More than 3,000 police and soldiers backed by armored personnel carriers raced into Brazil’s biggest slum before dawn Sunday, quickly gaining control of a shantytown ruled for decades by a heavily armed drug gang.

The takeover of the Rocinha neighborhood was the most ambitious operation yet in an effort to increase security before Rio hosts the final matches of the 2014 World Cup and the 2016 Olympics. Officials are counting on those events to signal Brazil’s arrival as a global economic, political and cultural power.

The head of state security and chief architect of Rio’s shantytown pacification program, Jose Mariano Beltrame, called the operation a major success and a big step toward breaking drug traffickers’ hold on key parts of Rio.

“We have taken over areas that for 30 or 40 years were in the hands of … a parallel power,” he said. “This is a very large area. It’s one of the biggest shantytowns in the Americas if not the world. We’re returning dignity and territory to people.”

The action in Rocinha is part of a campaign to drive the drug gangs out of the city’s slums, where traffickers often ruled unchallenged. The city of Rio de Janeiro has more than 1,000 shantytowns where about one-third of its 6 million people live.

Some estimates say the Friends of Friends gang brings in more than $50 million in drug sales annually in Rocinha and Vidigal alone.