And that ought to be the end of the story here in southern West Virginia, with its beleaguered mining industry and largely white population that fills the pews of evangelical churches on a Wednesday night as readily as on Sunday morning.

The region voted overwhelmingly Republican in the presidential contest two years ago, part of the historic defection of West Virginia Democrats, who hold a 2-to-1 registration advantage, from the national party over social issues like abortion and, more recently, opposition to environmental regulation.

And yet a Democratic congressman, Nick J. Rahall II, has defiantly held onto his seat here in the sparsely populated Third District, which runs from the rugged Appalachian coal fields in the west to the famed white-water rafting of the New River Gorge.

First elected in 1976, Mr. Rahall has had his campaign for a 20th term, against the Republican candidate, Evan Jenkins, become one of the most ferocious House races in the country. There is a torrent of outside money, blistering ads from conservative groups supported by the billionaire Koch brothers and a contest that after nearly $14 million in spending has come down, two weeks before voting, to a tossup.

While the race will not affect partisan control of the House, considered safely in Republican hands, it will make a statement about whether Democrats can survive in southern border states. The millions of dollars coursing through the inexpensive television markets of the state in Mr. Rahill’s contest are far more than in the race for West Virginia’s open Senate seat, where a Republican, Shelley Moore Capito, has taken a comfortable lead.

If Mr. Rahall hangs on, it will be because his ties to voters cemented over four decades — what supporters call his “brand” — overcome the antipathy of West Virginians to President Obama, and especially White House energy policy that many blame for hard times in coal country.

“Republicans have really turned the anger at Obama and the coal issue into an organizing principle,” Mr. Rahall said on Saturday during the Mercer County Democratic Party bean dinner in Princeton. “I probably have the most anti-Obama district represented by a Democrat in the nation.”

The race is clouded with distortions from both sides. Mr. Rahall says that Mr. Jenkins would take away miners’ black lung benefits. Mr. Jenkins accuses Mr. Rahall of supporting a carbon tax that raised electric rates. Fact-checkers have been busy debunking both claims.

Some of the antipathy of West Virginians to the White House would seem to defy economic self-interest. Mr. Rahall’s district includes some of the poorest counties in the state, where reliance on food stamps, Medicaid and other federal benefits is high. All would be rolled back under budgets passed by the House’s Republican majority.

The coal industry’s long decline is economically complex. When Alpha Natural Resources, one of West Virginia’s largest coal operators, warned 1,100 employees of potential layoffs in July, it blamed a worldwide glut of coal, competition from cheaper natural gas and lower-cost coal from western basins — as well as Environmental Protection Agency regulations.

But in the charged political arena, complexities fade and both sides identify a sole culprit for the industry’s struggles: the administration’s anti-coal regulations.

“Everyone knows Obama declared a war on coal. Nick Rahall stands with him,” says a television ad running this month by Freedom Partners Action Fund, a group supported by Charles G. and David H. Koch.

Image

Evan Jenkins, the Republican nominee. Democrats hold an advantage in registration, but voters have defected over social issues and environmental regulation.CreditRyan Stone for The New York Times

Mr. Rahall and his supporters have tried to turn the tables by attacking Mr. Jenkins’ wealthy backers. “The Koch brothers coming in here from New York, spending millions trying to elect Evan Jenkins. They’re not welcome, they don’t belong,” a miner says in an ad run by the Democratic Congressional Campaign Committee.

In a debate last week, Mr. Rahall boasted of “standing up to my party to stop the overreaching, overzealous, job-killing E.P.A. agenda.”

It is a tough argument to win, however, given the president’s desire to leave an environmental legacy of lower carbon emissions from power plants, as proposed by the E.P.A. this year.

Mr. Rahall has struggled to explain his vote in 2013 for a budget proposal by the Congressional Progressive Caucus, which included a $25 per ton carbon tax. He has said that he does not support a carbon tax and that he voted for the liberal budget blueprint, which badly failed in the House, to make a statement against Representative Paul D. Ryan’s Republican budget, with its many cuts to social programs. That plan passed the House but not the Senate.

Mr. Jenkins, who served in the State Legislature as a Democrat before switching parties last year, does not buy it. “This president has written off West Virginia,” he said. “He’s written off coal, and unfortunately, we’ve got a congressman who has helped him every step of the way.”

The air blitz against Mr. Rahall, 65, began nearly a year ago, almost unheard-of so early, when Republican-leaning national groups like the Chamber of Commerce and Americans for Prosperity — also supported by the Kochs — began attacking his vote for the Affordable Care Act.

Democratic groups sensed trouble and jumped in to counter the attacks. “We were effective in at least fighting back,” said Matt Thornton, a spokesman for the House Majority PAC, citing private polls that showed Mr. Rahall rebounding in the spring.

The National Republican Congressional Committee, which considers Mr. Rahall one of its top three House targets this year, has pumped more than $2 million into the race. “I think this is the first time people are starting to say maybe we like Nick Rahall but we don’t like what he’s doing in Washington anymore,” said Ian Prior, a spokesman for the Republican campaign committee.

Neither side is confident of victory and ads are booked through Election Day, for a total of $13.8 million for the cycle, according to a Democratic group that tracks ad spending.

On Saturday, Mr. Jenkins, 54, greeted voters at a celebration of the New River Gorge Bridge, where thousands walked across the impressive structure and watched parachutists drop 876 feet to the riverbed. “I’m Evan Jenkins, running for Congress, hoping for your vote,” the candidate told Nindo Punturi, who was working at one of many vendor booths.

“You’ll probably get it,” Mr. Punturi replied.

Kathy McGaha, a retiree, also offered support, saying she did not like Mr. Rahall. “He voted for everything with O-bummer,” she said.

Bernard Meadows, who worked in a coal mine in Mercer County for two decades “until they shut it down” in the 1980s, said he knew Mr. Rahall but was leaning in a different direction. “I just think it’s time for a change,” he said.

But when Mr. Jenkins approached Charles Treadway, he heard a different opinion. “I’ve been with Rahall for years, and I’ve got to stick with Nick,” said Mr. Treadway, a laid-off miner.

He said Mr. Rahall was being blamed unfairly for the troubles of the coal industry. “I put it simply: All you’ve got to do is follow the money,” he said, adding that cheap natural gas prices were the reason many miners were out of work.

A version of this article appears in print on , on Page A16 of the New York edition with the headline: Race Tests Democrats’ Viability in West Virginia. Order Reprints | Today’s Paper | Subscribe