Sen. Ted Cruz (R-TX) capped a better-than-expected Super Tuesday with an overnight win in Alaska, the only West Coast state to vote in the 12-state mega-primary.

Though Republican frontrunner Donald Trump led through most of the night’s counting, Cruz won the caucus by a small margin in the end.

As the Anchorage Daily News reported:

Cruz had 36.4 percent of the vote compared to Trump’s 33.5 percent, according to the unofficial results from the party. Trump and Cruz were separated by 627 votes, or 2.9 percentage points.

Sen. Marco Rubio of Florida was well behind with 15.1 percent, retired neurosurgeon Ben Carson had 10.9 percent and Ohio Gov. John Kasich had a meager 4.1 percent.

Cruz dominated in voting around Alaska’s main cities: Anchorage, Fairbanks, and Juneau. Trump won in the rural north, northwest, south-central and southeast. Dr. Ben Carson won the vote in a state house district in the southwest.

Cruz will take 12 of Alaska’s delegates, while Trump won 11 and Rubio won five.

Turnout for the Alaska caucus was 21,930 — much higher than the 14,100 who voted in 2012.

Polling for the state had been spotty, with Trump winning the most recent poll in January by 4%.

Cruz’s unexpected win is a political blow to former Gov. Sarah Palin, who endorsed Trump before the Iowa caucuses.

The Alaska win brought Cruz’s total number of wins to three states, including his home state of Texas and neighboring Oklahoma. Trump won seven states, and Rubio won one state, Minnesota.

Cruz’s strong result in Texas, where he won a staggering 44% of the vote, helped him haul in 57 delegates there, nearly three-fourths of the total.

But Trump won the most delegates on the night, taking 203 to Cruz’s 144, widening his lead to 285-161 in the primary.