The deadly clash in the state of Guanajuato is said to have occurred when security forces sought to search a home. Elsewhere, in the state of Sonora, a congressional candidate escapes assassination.

MEXICO CITY — A shootout between authorities and gunmen in central Mexico left at least 12 people dead Friday, hours after a congressional candidate survived an apparent assassination attempt in the northern part of the country.

The incidents underscored the broad reach of violence plaguing Mexico amid a government crackdown on drug traffickers and signs that gangs have sought to infiltrate local politics.

Friday's gunfight pitted Mexican soldiers and state and federal police against heavily armed gunmen in Guanajuato state, a farming belt in the nation's midsection not known as a drug hot spot.

Gov. Juan Manuel Oliva told reporters that all 12 who died were gunmen. He said three state police officers were wounded.

Authorities said police came under fire when they attempted to search a home in a community of rural Apaseo el Alto municipality. The municipality was the scene of a shootout two days earlier during which gunmen hurled a grenade at police, an increasingly common tactic in Mexico's drug war.

Even tiny rural towns have been scenes of shootouts since President Felipe Calderon launched an army-led government offensive against organized crime in December 2006. About 11,000 people have died in drug-related violence, largely due to clashes between rival drug gangs over control of smuggling routes and street sales.

In the northern state of Sonora, Ernesto Cornejo Valenzuela, a mayor on leave to run for Congress under the banner of Calderon's National Action Party, escaped unhurt after attackers opened fire Thursday night.

Two of Cornejo's aides died and three others were wounded during the shooting, which took place after a campaign event in southern Sonora. Mexicans vote July 5 for congressional representatives, as well as hundreds of state and local positions.

Authorities did not disclose a possible motive for the attack, which was under investigation by federal prosecutors. Sonora, which sits across the border from Arizona, has a long history of drug- and migrant-smuggling.

The drug war has put a spotlight on drug traffickers' infiltration of the political system, particularly at the local level, where they offer bribes or make threats to get officials to cooperate.

More than a dozen mayors or other City Hall officials have been killed nationwide during the last year and a half. Federal authorities rounded up 30 local and state officials in the state of Michoacan last month for suspected ties to a crime group known as La Familia. All but three have been imprisoned while awaiting trial.