The Institutional Revolutionary Party that ruled Mexico for most of the 20th century was battling to retake Tijuana and cling to the governorship of Oaxaca as voters cast ballots Sunday in state and local elections that could shape the 2006 presidential race.

As balloting ended here, both major mayoral candidates -- gambling magnate Jorge Hank Rhon of the Institutional Revolutionary Party, or PRI, and Jorge Ramos of President Vicente Fox's National Action Party, or PAN -- claimed a narrow victory on the basis of rival exit polls.

In the southern state of Oaxaca, the Televisa television network said its exit poll was so close that it could not predict a winner. Supporters of the PRI and an opposition coalition backed by the Fox's conservative party and the leftist Party of the Democratic Revolution, or PRD, both began tentative victory celebrations.

With the PAN losing strength nationwide, the two races were a test of the resurgent PRI's ability to shore up its heartland rural base, which encompasses thousands of poor indigenous communities in Oaxaca, and its attempts to erode the PAN's urban strongholds in northern Mexico.

Early exit polls in Sunday's other election showed PAN candidate Luis Armando Reynoso Femat trouncing the PRI in the gubernatorial race in Aguascalientes, a small industrial state in north-central Mexico that has been run by the PAN since 1998.

For six decades, every state election went to the PRI, by fair means or foul. The party lost its monopoly in 1989, ceding the Baja California statehouse to the PAN. The PRI's 71-year domination of the presidency ended with Fox's election victory in 2000.

But Fox's inability to deliver on promises to make Mexicans safer and more prosperous has put his party on the defensive against the PRI and the smaller PRD. Both gained in last year's mid-term congressional elections, and the PRI remains the largest, best-organized party, holding most statehouses and a plurality in Congress.

Roberto Madrazo, a former governor of Tabasco, has steadily rebuilt the PRI electoral machine since he became party boss in 2002. But his heavy-handed leadership has alienated rivals in the party as it gears up for the race to succeed Fox, who is limited to one six-year term.

The PRI candidates in Oaxaca and Tijuana were handpicked by Madrazo, making Sunday's elections a test of his ability to dominate the party and gain its presidential nomination.

In Tijuana, Mexico's fifth-largest city, Hank's vigorous campaign intrigued the 1.2 million residents and galvanized the party for its first serious run on city hall since the PAN's statewide sweep of 1989. Hank started the race in the spring 25 percentage points behind the PAN's Jorge Ramos, 36, a lackluster career bureaucrat and former city council member, but narrowed the gap substantially in final pre-election surveys.

One of Mexico's wealthiest men, Hank is a son of the late Carlos Hank Gonzalez, a PRI power broker who built a business empire while in office. He often brandished the motto, "A politician who is poor is a poor politician."

The younger Hank, 48, is a political novice, an eccentric multimillionaire who dresses outlandishly, has 18 children by four women, and boasts a private zoo of 20,000 animals. He owns a nationwide chain of betting parlors and runs Tijuana's greyhound racetrack.

Hank's campaign was a surprise hit, especially in the poor "colonias," where he paid for public works and other giveaways. He out-charmed his foe in debates and wooed voters with promises to fight crime and to make this violence-wracked city as clean and livable as San Diego.

Yet Hank was plagued by his association with the 1988 murder of a Tijuana journalist -- a crime for which two of his bodyguards were convicted -- plus allegations that he has laundered money for the Tijuana-based Arrellano Felix drug-smuggling ring, and statements by a federal prosecutor naming him as a suspect in the June 22 slaying of a crusading local editor. Hank Rhon has denied those allegations and no charges have been filed against him.

Voters cast ballots in San Pedro Ixtlahuaca on the outskirts of Oaxaca. In a nearby village, groups of men were reportedly intimidating voters.Ulises Ruiz of the PRI, left, and coalition candidate Gabino Cue Monteagudo were in a tight race in Oaxaca state's volatile gubernatorial contest.