Sen. Ted Cruz speaks with his wife, Heidi, by his side during a primary night campaign event in Indianapolis. Cruz ended his presidential campaign, eliminating the biggest impediment to Donald Trump’s march to the Republican nomination.

May 3, 2016 Sen. Ted Cruz speaks with his wife, Heidi, by his side during a primary night campaign event in Indianapolis. Cruz ended his presidential campaign, eliminating the biggest impediment to Donald Trump’s march to the Republican nomination. Darron Cummings/AP

Donald Trump still leads the Republican presidential race, but Ted Cruz continues to beat him at a trickier game: securing convention delegates in states that don’t hold caucuses or primaries.

Meanwhile, on the Democratic side, Sen. Bernie Sanders failed to make any headway in his delegate deficit, despite winning Saturday’s caucuses in Wyoming.

The events in neighboring states underscored the unpredictability of the race for the delegates who will choose the presidential nominees.

If Trump fails to secure the 1,237 delegates needed to win the GOP nomination before the July convention in Cleveland, his missteps in the more obscure delegate contests such as Colorado’s could cost him a victory.

On Saturday, Cruz swept all the available delegates in Colorado during a day-long state convention.

Republican presidential candidate Ted Cruz took aim at rival Donald Trump saying, "It's easy to talk about making America great again," but you need to know what "made America great." (Reuters)

“We have beaten Donald Trump,” Cruz told convention attendees here as he stood onstage in a hockey arena flanked by supporters in bright orange T-shirts.

The senator’s appearance capped more than a year of work by his volunteers and staffers in Colorado, one of six states and territories that hold a convention instead of caucuses or a primary to determine its presidential preference. By the end of the day, Cruz had won all of the state’s 34 delegates.

The win pales in comparison to Trump’s victories in larger, winner-take-all states. Trump still holds a commanding lead in total delegates, and polls show he is far ahead of Cruz in New York, which holds its primary April 19. But the proceedings here Saturday exposed embarrassing missteps by Trump, part of the reason he has shuffled his campaign team.

In the hours before Saturday’s vote, Trump supporters distributed white fliers to convention attendees with the names of candidates to fill 13 statewide delegate slots. But several names were misspelled or assigned the wrong ballot number.

The gaffe was exposed just as Republicans were walking onto the arena floor to take seats and prepare to cast ballots. Trump volunteers printed new lists with new names and ballot numbers — but those lists also had mistakes, including the wrong ballot numbers or the names of people who had pledged to vote for Cruz.

Alan Cobb, a Trump campaign senior adviser in Colorado for the convention, accused the state party of changing the ballot numbers in the final hours before the vote.

“Awful process,” he said in a text message. “Our slate was correct at the time of print.”

View Graphic Tracking the race to the Republican nomination

Trump supporters conceded that their team was coming up short. “I’ve been in politics exactly 37 days,” said Pamela Gentry, a real estate agent and contractor from Westcliffe, Colo., who was loudly drawing attention to a Trump campaign booth just off the arena floor.

Gentry said she began organizing a slate of Trump delegates when she realized the campaign hadn’t deployed staffers to the state.

“It would have been nice if it was a couple of months ago. Because I think every delegate counts,” she said.

Sanders, who won Saturday’s Democratic caucuses in Wyoming, got a reminder of his uphill quest to catch up to front-runner Hillary Clinton’s delegate lead. The Democrats were each awarded seven delegates, evenly splitting the state’s 14 delegates even though Sanders commanded a 56 percent to 44 percent margin of victory with all precincts counted.

Sanders, nevertheless, claimed momentum from the contest.

“It is beyond debate that the momentum in the campaign is with us,” he told reporters after a rally in Queens.

Elsewhere on Saturday, Republicans in Iowa, Indiana, Michigan and Virginia also began assigning people to serve as delegates to the national convention in July, which could become the party’s first contested convention in four decades.

In the nomination race, Trump has 743 delegates, and Cruz climbed to 566 with his win Saturday. Sen. Marco Rubio (R-Fla.), who dropped out of the race last month, still has 171 delegates, and Ohio Gov. John Kasich has 143.

Most delegate trackers forecast that Trump needs to win slightly more than 60 percent of the remaining available delegates to win the nomination before the July convention. Until then, the process of picking delegates will continue to earned outsize scrutiny.

In Virginia’s 9th Congressional District, Republicans elected their three delegates. Two of the winners said they would vote for Cruz if voting on a GOP nominee goes into multiple rounds; one said he would support Trump, who easily won the state’s southernmost congressional district.

In Michigan, Republicans formally awarded Trump 25 delegates, and Cruz and Kasich 17 delegates each. The Trump and Kasich teams blocked the Cruz slate from earning any of the state’s eight seats on convention committees that will set the convention rules and write the party platform.

Iowa began the process of selecting its GOP delegates, and Cruz won 11 of the 12 seats up for grabs Saturday. He also won five of the state’s eight convention committee assignments. The senator won the state in February and Trump placed second, meaning both will eventually pick up at least some of the state’s 30 delegates.

But Colorado’s colorfully chaotic proceedings were the most intriguing of the weekend.

“Isn’t democracy messy? It’s messy and wonderful, and I love it,” said Joy Hoffman, chairwoman of the Arapahoe County GOP. “Every time we do this, this is proof of the success of the greatest experiment we have.”

Jerry Demey, a 73-year old delegate from Pueblo, Colo., marveled at the attention the convention was earning from the national media.

“Thank you, Donald Trump,” he said. Despite Cruz’s organizational prowess in Colorado, he said that the businessman “got more people off their a-- this year than I’ve ever seen before.”

John Wagner in New York contributed to this report.