In a potential major upset in the making, San Rafael Councilman Marc Levine held a slight but steady lead over incumbent Assemblyman Michael Allen on Tuesday night in their battle for the 10th Assembly District seat.

With all precincts in, Levine held 50.6 percent of the votes to Allen's 49.4 percent.

"I'm cautiously optimistic about the outcome tonight," Levine said from his campaign party at Aurora Art Studios in San Rafael.

Levine never trailed throughout the evening. The outcome could hinge on about 106,000 mail-in ballots that went out in Sonoma and Marin counties.

David McCuan, a political scientist at Sonoma State University, said a Levine victory would be a "huge" blow for the Democratic Party establishment in Sacramento and for Assembly Speaker John Perez.

The Democratic Party steered a significant amount of money and resources to back Allen, a former union leader who rose quickly through the ranks of power in his first Assembly term to become assistant majority floor leader. Many observers gave Levine no chance of winning.

"If Levine defeats the No. 4 guy in Sacramento — which Allen is — that is huge not only for Democrats in California, but also for the future of Perez as speaker. That's how big this is," McCuan said.

Allen and Levine were vying to represent voters in a newly created district that spans Marin County, part of Santa Rosa and portions of western and southern Sonoma County.

The pair earned the right to compete for the district seat under California's new top-two primary system. The race gained attention in part because it was one of about two dozen in the state pitting members of the same party against one another in the general election.

Allen did not immediately return a message seeking comment Tuesday.

Allen, who was elected to represent the 7th Assembly District, rented an apartment in San Rafael to establish residency within the new district.

Allen was on target to spend nearly $1 million in his bid, outspending Levine nearly 3 to 1. In addition, independent expenditure committees poured in about $700,000 to help Allen win. Levine also received a boost of $250,0000 from two independent expenditure committees.

"I don't think anyone believed we would be this competitive, but I'm proud we've given the voters of Sonoma and Marin (counties) a choice," Levine said.

In other state legislative races featuring North Coast candidates, Democratic incumbents appeared to be holding on to early leads.

In the 2nd Assembly District race, with all precincts reporting, incumbent Wes Chesbro of Arcata held 63.5 percent of the votes to the 36.5 percent held by Guerneville contractor Tom Lynch Tuesday.

With all precincts reporting, in the 4th Assembly District race, which covers parts of Rohnert Park and the Sonoma Valley, Assemblywoman Mariko Yamada, D-Davis, had 62.1 percent of the votes to Republican challenger's John Munn's 37.9 percent. Munn is also from Davis.