WASHINGTON — Third-party candidates are usually an afterthought in presidential elections, but Libertarian nominee Gary Johnson and Green Party nominee Jill Stein could impact the outcome of this year’s race, analysts say.

Stein’s leftist base and appeal to Bernie Sanders’ supporters are a natural drain on Hillary Clinton.

But polls show Johnson, a former Republican governor of New Mexico, is unexpectedly picking off more supporters from the Democratic nominee than Republican Donald Trump in some states.

“Johnson tends to hurt Clinton slightly more than Trump,” Geoffrey Skelley, of the University of Virginia Center for Politics, told The Post. “This is surprising because Libertarian voters tend to be predominantly male and white, two demographics that are more Republican-leaning as a whole.”

It appears that anti-Trump Republicans and independents are turning to Johnson as an alternative instead of Clinton.

The third-party contenders are major factors in Colorado, Arizona, North Carolina, Georgia and Texas, a new Washington Post/SurveyMonkey poll shows.

Clinton is winning or tied in those states, but the inclusion of the third-party candidates appears to work in Trump’s favor.

In Colorado, for example, Clinton enjoyed a 10-point lead over the GOP nominee in a head-to-head matchup last month.

But with the race tightening and third-party candidates included in the polls, the Colorado race is tied at 37 percent, with Johnson pulling 16 percent and Stein 6 percent.

“Nothing is settled at the moment, everything from Trump making a comeback to people just ultimately deciding to vote for Gary Johnson,” said Floyd Ciruli, a Denver pollster.

He noted that Clinton pulled her advertising in Colorado when she was up 10 points, but now both Johnson and Trump are on the air.

Johnson and Stein both have improved their poll numbers nationally since the start of the summer, with him averaging about 9 percent and her 3.5 percent.

Those polls were conducted before Johnson made a remarkable gaffe, admitting on MSNBC that he had no idea what Aleppo was. Aleppo is a Syrian city is at the epicenter of the refugee crisis.

Third-party candidates have gained ground because plenty of voters just can’t stomach the major-party nominees.

“There is a fertile environment in the electorate for a third-party candidate because there is a sentiment of aversion to Trump and Clinton that has reached very high levels,” said Michael Cornfield, associate professor at George Washington University’s Graduate School of Political Management.

“In an environment where there is dread of making a choice between the two, that presents an opportunity for a third-party candidate.”