ANCHORAGE, Alaska (Reuters) - Alaska Governor Bill Walker, a political independent, halted his re-election campaign on Friday and endorsed his Democratic challenger, ending a three-way contest in which neither had appeared capable of defeating the Republican front-runner.

With just 18 days left before the Nov. 6 election, Walker said he concluded that he could not win a second term in a race against both former U.S. Senator Mark Begich, a Democrat, and former state Senator Mike Dunleavy, a Republican.

Walker, 67, said his decision to bow out was based entirely on what he felt was “best for Alaska” and involved no deal with the Democrat or any promise of a role in a Begich administration should he win.

Walker’s withdrawal came three days after his former running mate, Byron Mallott, a Democrat and the first Alaska Native elected to statewide office, abruptly resigned as lieutenant governor over admitted but unspecified “inappropriate comments” in a scandal that threw the governor’s campaign into disarray.

But public opinion surveys were already showing Dunleavy, 57, running well ahead of the two other men and indicated Begich, 56, had greater support than the incumbent governor.

After consulting for days on whether Walker or Begich had a better shot at running a competitive race against Dunleavy, the determination was made that “Begich has the better odds,” the governor said in a statement posted on his campaign’s website.

Walker also said Begich’s positions on various key issues “more closely align with my priorities for Alaska,” including their support for Medicaid expansion in Alaska and state action on climate change. Dunleavy opposes both.

“Today’s developments leave Alaska voters with a clear choice,” Dunleavy’s campaign said after learning Walker halted his re-election campaign.

A former teacher and outspoken supporter of President Donald Trump, Dunleavy had focused his campaign on criticizing Walker for reducing the annual oil-fund dividends all Alaska residents receive.

Walker has said limiting the payout was necessary to address big budget deficits. Dunleavy has advocated deeper spending cuts and more oil and mining development.

The latest announcement came at the annual convention of the Alaska Federation of Natives, a powerful constituency in the state, just before Walker, Begich and Dunleavy were all scheduled to participate in a gubernatorial debate.

Begich and Walker, whose name will remain on the ballot despite his withdrawal, were widely seen as likely to take votes away from each other in a three-way race. Begich, a one-time Anchorage mayor who served six years as a U.S. senator from Alaska ending in 2015, called Walker’s move “unbelievably gracious.”

Walker changed his party affiliation from Republican to independent before launching his successful 2014 campaign for governor on a “unity” ticket with Mallot as his running mate.

In that election, Walker unseated the Republican incumbent, Sean Parnell, who had been lieutenant governor under Sarah Palin, the one-time Republican U.S. vice presidential nominee, and he became governor in 2009 when she quit.

Walker’s campaign spokesman previously acknowledged that the governor and Begich had been in talks for days to discuss a “path forward that’s best for Alaska.” Begich told reporters Friday night he did not know of Walker’s decision until just before it was announced.

(This version of the story in paragraph 9, removes incorrect description of Dunleavy as “retired Air Force lieutenant colonel”, clarifies he was a former teacher)