Democrat Earl Ray Tomblin held on for a slim victory in a special election for governor of West Virginia Tuesday, narrowly preventing a third state special election embarrassment for President Barack Obama.

Longtime politician Tomblin, the acting governor, defeated mining engineer Bill Maloney, who has never held elected office, by about 3 percentage points.

With 99 percent of precincts reporting, Tomblin, 59, led Maloney by 50 percent to 47 percent, or about 8,500 votes. Three other candidates had scattered support, including one associated with the Green Party, who won 2 percent.

The court-ordered special election became as much about the president as about the candidates on the ballot in the last days before the vote.

Outside groups poured millions of dollars into the contest, recognizing that a third special election loss for a Democrat within just the past three weeks would have been especially damaging as Obama's 2012 re-election bid gears up.

The Democratic Governors Association spent $2.4 million on the race, and the Republican Governors Association spent $3.4 million, including a spot that began running a few days ago in the expensive Washington, D.C., media market, which covers only a small part of the state, tying Tomblin to Obama's health care law.

Tomblin said his victory showed outsiders could not influence the state's voters. The conservative Democrat, who campaigned on his experience and West Virginia's relatively strong economic position, did not mention Obama or any other national party leader in his victory speech, and he promised he would work with members of both parties.

We were able to fight back against those who wanted to bring in extreme ideas and create the turmoil seen in Washington, he told supporters.

West Virginia's budget is balanced and, although the state has the nation's second-lowest per capita income, its unemployment rate is 8.1 percent, a point below the national level.

Maloney told his supporters he had called Tomblin to congratulate him, and urged them to work with the Democrat.

NO REPEAT OF NEW YORK

In September, Democrats lost special elections for U.S. House of Representatives seats from New York and Nevada. Republicans trumpeted the New York victory for a seat held by Democrats for decades as evidence of voter discontent.

Although West Virginia reliably backs Republicans in presidential elections, a Democratic defeat would have been taken as a sign Obama is dragging down his party, because the state has not had a Republican governor for 10 years.

Neil Berch, a political science professor at West Virginia University, said Tomblin's victory showed Democrats did better at getting voters to the polls and that Tomblin's positions were more in tune with the state's voters, while Maloney was still little known.

It would have been a different race with a more liberal Democrat, or with a more moderate Republican, he said in e-mailed comments after the result. Maloney did a good job of defining Tomblin, but maybe not such a good job of defining himself, Berch said.

Republican John McCain defeated Obama easily in West Virginia in the 2008 presidential election. Obama's popularity has since declined in the state, although Democrats hold a nearly 2-to-1 voter registration advantage over Republicans in West Virginia.

Tomblin released ads showing him with Joe Manchin, the former governor whose election to the U.S. Senate led to the court-ordered election. Manchin has distanced himself from the White House, particularly on opposition to the Environmental Protection Agency, seen in West Virginia as a threat to crucial coal industry jobs in a state with the country's second lowest per capita income.

The special election was held only to fill the end of Manchin's term. West Virginia will hold another gubernatorial election in November 2012.

(Additional reporting by Steven Allen Adams; Editing by Peter Cooney)