Updated

Drug gangs set fire to buses and opened fire on police stations and posts around Rio de Janeiro early Thursday in a wave of violence that killed 18 people, the state's top law enforcement officer said.

The victims included seven who were burned to death in one of four torched buses and two policemen, said Roberto Precioso, head of Rio's Public Safety Department.

Two other civilians were gunned down, including a street vendor caught in the crossfire of a shootout in Rio's Botafogo district, he said. Seven alleged gang members were also killed.

Click here to visit FOXNews.com's Americas center.

Precioso said gang members used handguns, machine guns and grenades in 12 attacks against police stations and outposts that began in the early morning.

Fourteen civilians and eight police officers were injured, he added.

Precioso said the attacks were apparently a show of force staged before a new governor is sworn in on Jan. 1. Police intelligence had warned the gangs were planning the attacks for some time.

"It is very difficult to prevent these types of attacks that were practically kamikaze," Precioso said at a news conference. "Police action prevented the situation from getting much worse."

He said the attacks were apparently ordered from inside one of the state's prisons, but did not elaborate.

According to the Web site of the O Globo newspaper, the attacks began on the Washington Luiz highway that links Rio de Janeiro with the nearby mountain resort of Petropolis.

Most of the violence occurred on Rio's poor north side, although a policeman was killed in the upscale Lagoa district and a woman was killed in an attack on a police booth in the Botafogo district near downtown.

Rio Mayor Cesar Maia said gangs appeared to be retaliating against militias — reportedly run by off-duty police officers — that in recent months have been battling the drug gangs in slums and charging residents for protection.

"The reason for what's happening is that militias have grown and the drug gangs are leaving," Maia told reporters. "To maintain their income, the gangs are increasing crime on the street."

Precioso said early action by Rio's police had prevented the violence from reaching levels seen in Sao Paulo, Brazil's largest city, in May when an organized crime group launched similar attacks that left nearly 200 people dead, including some 40 police and dozens of alleged gang members.

Retired Judge Walter Fanganiello Maierovitch, an expert on organized crime and Brazil's former drug czar, said police in Rio did a better job of containing the attacks.

"Precioso did not try to fool anyone and took to the offensive immediately," Maierovitch told CBN radio. "In Sao Paulo authorities downplayed the attacks at first, saying they were isolated incidents."

Still, he said, the violence shows that "Brazil's public safety polices are in shambles," adding that the attacks were a "chronicle of a tragedy foretold."

Precioso said police were working to contain ongoing attacks and that they did not present a danger to the millions expected to ring in the New Year on Rio's beaches.

But he declined to answer a reporter's question about whether the police are prepared to handle security during the 2007 Pan American Games that will take place here.

Rio de Janeiro is one of the most violent cities in the world, with an annual murder rate of about 50 per 100,000 residents.

Click here to visit FOXNews.com's Americas center.