RIO DE JANEIRO — One of Brazil’s most-wanted drug lords has been captured, the authorities here announced Thursday, taken around midnight from the trunk of a car while he was attempting to flee Rocinha, one of this city’s largest slums, ahead of a bid by security forces to seize control of the sprawling hillside territory.

The suspect, Antônio Bonfim Lopes, 35, is known as Nem and is renowned here for extravagant tastes that include Armani suits and renting a helicopter for his wife to tour Rio from the sky.

Mr. Lopes is accused of heading a cocaine-trafficking organization with more than $5 million in monthly revenue, and he has been hunted for years. But he is believed to have only rarely left his bastions in the slum, including a luxurious lair he created in a three-story villa equipped with a gym and swimming pool.

Rocinha — the slum controlled by Mr. Lopes — is situated above some of Rio’s most exclusive residential districts. Police squads had begun stationing themselves in recent days around its entrances in anticipation of a broader push into the community as part of the authorities’ “pacification” project, aimed at asserting control over Rio’s slums in preparation for the 2014 World Cup and the 2016 Summer Olympics.