Texas Sen. Ted Cruz ended his presidential campaign on Tuesday after failing to top Donald Trump in the Indiana Republican primary.

view photo essay The presidential campaign: Ted Cruz The Texas senator was first to announce his bid back in March, and has since been carefully laying the groundwork for a come-from-behind primary victory.

“From the beginning, I’ve said that I would continue on as long as there was a viable path to victory,” Cruz told supporters at an election night rally in Indianapolis. “Tonight, I’m sorry to say it appears that path has been foreclosed.”

A surprised crowd gasped and booed as Cruz made the announcement.

“Together we left it all on the field in Indiana,” Cruz said. “We gave it everything we got. But the voters chose another path.”

NBC News projects Cruz will finish second in the Hoosier State, well behind Trump in a state that was crucial for Cruz to win in order to prevent Trump from gaining the 1,237 delegates needed to secure the presidential nomination.

Trump’s commanding victory is projected to deliver him well over 40 delegates, making it unlikely the front runner fails in getting a majority of the delegates.

In the final weeks of his campaign, Cruz made a number of unconventional moves in the hopes of bolstering a campaign that was running well behind Trump in the polls. He and Ohio Gov. John Kasich entered into an informal pact, each announcing they would not compete in states where the other was running closer to Trump.

.@realDonaldTrump will be presumptive @GOP nominee, we all need to unite and focus on defeating @HillaryClinton #NeverClinton — Reince Priebus (@Reince) May 4, 2016

But hours after both campaigns announced the agreement, Kasich said his supporters in Indiana should still vote for him. From there, neither of the two candidates formed much of an alliance, and an NBC News/Marist/Wall Street Journal poll showed voters overwhelmingly opposed the agreement.

Cruz then named former rival Carly Fiorina as his potential running mate. Trump called the move a sign of desperation that would do little to change the outcome in Indiana.

And despite the informal alliance Cruz and Trump had in the early stages of the primary battle, the fight between the two grew increasingly nasty and personal in its final stretch. On Tuesday morning, after Trump repeated a debunked tabloid story tying Cruz’s father, Rafael Cruz, to the assassination of President John F. Kennedy, the senator delivered a stinging and personal takedown of his rival.

RELATED: Trump wins Indiana primary, setting path to GOP nod

“Donald Trump is a serial philanderer and he boasts about it,” Cruz said Tuesday morning. “This is not a secret, he is proud of being a serial philanderer.”

Cruz did not mention Trump in his remarks ending his campaign.

Following Cruz’s announcement, Republican National Committee head Reince Priebus tweeted that Trump will be the presumptive nominee, even though Kasich’s campaign staff vowed they would remain in the race.

Republicans committed to stopping Trump also vowed to continue on in a statement released ahead of Cruz’s announcement.

“We continue to give voice to the belief of so many Republicans that Trump is not a conservative, does not represent the values of the Republican Party, cannot beat Hillary Clinton, and is simply unfit to be president of the United States,” Katie Packer, chair of Our Principles PAC, said in a statement. “We will continue to educate voters about Trump until he, or another candidate, wins the support of a majority of delegates to the Convention.”

This story originally appeared on NBCNews.com.