WASHINGTON — They campaign in near anonymity, these third-party contenders who stand no shot at the presidency. Their supporters are castigated for wasting their votes. But don’t write them off just yet. In hotly contested swing states, their presence on the ballot may alter the course of the election.

In Virginia, where Mitt Romney and President Obama are running neck and neck, former Republican congressman Virgil Goode’s crusade for the Oval Office could draw conservatives and tip the state away from Romney. In “live free or die” New Hampshire, Libertarian Gary Johnson, the former Republican governor of New Mexico, is a wild card, potentially siphoning votes from both Romney and Obama. And in Colorado, where a marijuana initiative is on the ballot, Johnson’s support for legalizing marijuana could hurt Obama among young voters.

Also running are Green Party nominee Jill Stein, a physician from Lexington who had run against Romney for Massachusetts governor in 2002, and Rocky Anderson, of the newly formed Justice Party and a former Democratic mayor of Salt Lake City.

The Romney and Obama campaigns scoff at the possibility of a third-party spoiler. But Goode’s popularity among some Virginians worried Republican leaders enough that they tried to strike the Constitution Party nominee from the ballot in the battleground state. Republican voters have urged Goode to withdraw, and Virginia’s Republican governor, Bob McDonnell, has even gone on air warning that a vote for Goode would only help keep Obama in the White House.

Get Political Happy Hour in your inbox:

Your afternoon shot of politics, sent straight from the desk of Joshua Miller.

“In an incredibly tight election, any number of votes going to a third party could be significant,” said Whit Ayres, a GOP strategist. “You can never dismiss any concern. Just ask Ralph Nader and Al Gore.”

Gore’s narrow loss to Republican George W. Bush in 2000 was widely attributed to Nader, the Green Party nominee who took votes from Gore in the swing states of New Hampshire and Florida. Bush won New Hampshire — and its four electoral votes — by a 7,000-vote margin over Gore, with Nader winning more than 22,000 votes.

But the chances of a repeat scenario occurring in New Hampshire are slim. In a University of New Hampshire poll of likely voters last weekend, only four out of 773 people supported Johnson, said Andrew E. Smith, the director of the university’s survey center. None said they would vote for Goode.

Johnson, who initially entered the race as a Republican in the months leading up to the New Hampshire primary before his run as a Libertarian, said he is actively courting voters who had supported former Republican candidate Ron Paul with his message of personal freedom. If a significant number of the 56,000-plus voters who supported Paul in the primary shift to Johnson, who earned a mere 181 votes in the primary, that could make a major difference in swaying the election, said Linda Fowler, a
Dartmouth College professor.

Jim McClarin,a 66-year-old carpenter from Nashua, supported Paul in the primary and now plans to vote for Johnson, who is on the ballot in 48 states. While McClarin views Romney as a small improvement over Obama, he thinks bothanswer to powerful interest groups.

“Romney would have to do back flips to get my vote, and even then I’m not so sure because he’s stood for so many things at different times,” McClarin said.

Johnson, 59, is wrapping up a national tour of colleges, including the University of New Hampshire, trumpeting his agenda of balancing the federal budget, ending foreign wars, legalizing marijuana, and allowing gay marriage. Not taking any chances, Republicans deployed Kentucky Senator Rand Paul, son of Ron Paul, to speak to college students in New Hampshire on behalf of Romney last weekend.

In Virginia, a critical state that Obama won in 2008, Romney’s efforts to secure its 13 electoral votes could be threatened by Goode’s candidacy. The former Democrat turned independent turned Republican represented the south central pocket of the state in Congress for 12 years and is on the ballot in about two dozen states.

Goode, 66, appeals to working-class voters in impoverished tobacco country in part because of his desire to end illegal immigration and curb legal immigration until unemployment falls below 5 percent. He would also end automatic citizenship for US-born children of illegal immigrants.

“I’m consistently prolife, pro-traditional marriage, and Romney has flipflopped on those issues,” Goode said as his wife drove him from a campaign event in Indiana to another in Ohio. “The Republicans are scared. They have probably spent half a million dollars to get me off the ballot.”

A Washington Post poll of registered voters in Virginia last month showed Goode with 2 percent. Johnson received 4 percent and Stein, 1 percent. Anderson was not in the poll.

“Even if [Goode] wins only one or two percent, he can be the difference,” said Larry Sabato, of the Center for Politics at the University of Virginia. “Virgil is well known and has a lot of people who like him.”

John K. Rooney, a 49-year-old investment adviser who had a Tea Party group in Petersburg, said he has encountered criticism from his own members for supporting Goode.

“They say, ‘Oh, if you don’t vote for Romney you’re going to give the election over to Obama,’ ” Rooney said. “But I’m certainly not going to vote for the lesser of two evils. And who’s to say Romney is better than Obama?”

The platforms of third-party candidates have been relegated to the fringes. They were shut out of the three presidential debates and resigned to running no-frills campaigns on meager budgets.

Stein and Johnson sued after being blocked from debating Romney and Obama; Stein was arrested trying to get into the Hempstead, N.Y., debate.

Instead, the four candidates outlined their messages Tuesday in a Chicago hotel ballroom during a separate debate moderated by Larry King and televised on C-SPAN.

Stein, 62, said she is trying to appeal to disenfranchised voters who rallied to the Occupy Wall Street movement and is calling for tuition-free colleges, Medicare for all ages, and clean energy policies.

“Progressives this time aren’t saying ‘Obama is the answer,’ ” Stein, who is on the ballot in 38 states, said in an interview. “They’re saying, ‘He’s not as a bad as Romney.’ ”

Anderson, 61, is on the ballot in only 15 states and holds no illusions that his candidacy will swing the election. He said he just wants to make voters aware of how the two-party political system betrays the public interest. He promises to end foreign wars and the war on drugs, and advocate for a single-payer health system.

BostonGlobe.com complimentary digital access has been provided to you, without a subscription, for free starting today and ending in 14 days. After the free trial period, your free BostonGlobe.com digital access will stop immediately unless you sign up for BostonGlobe.com digital subscription. Current print and digital subscribers are not eligible for the free trial.

Thanks & Welcome to Globe.com

You now have unlimited access for the next two weeks.

BostonGlobe.com complimentary digital access has been provided to you, without a subscription, for free starting today and ending in 14 days. After the free trial period, your free BostonGlobe.com digital access will stop immediately unless you sign up for BostonGlobe.com digital subscription. Current print and digital subscribers are not eligible for the free trial.