Washington (CNN) Ted Cruz endorsed Donald Trump for the presidency Friday afternoon, a stunning turn of events after a contentious primary filled with nasty personal attacks and a dramatic snub at the Republican National Convention.

"After many months of careful consideration, of prayer and searching my own conscience, I have decided that on Election Day, I will vote for the Republican nominee, Donald Trump," Cruz wrote in a Facebook post

"A year ago, I pledged to endorse the Republican nominee, and I am honoring that commitment. And if you don't want to see a Hillary Clinton presidency, I encourage you to vote for him."

"I am greatly honored by the endorsement of Senator Cruz," Trump said in a statement obtained by CNN. "We have fought the battle and he was a tough and brilliant opponent. I look forward to working with him for many years to come in order to make America great again."

The move -- three days before Trump's critical first debate with Clinton -- comes as the Trump and Cruz camps have moved closer in recent weeks.

Trump's vice presidential nominee Mike Pence played a key role in bringing Cruz into the fold. Pence and Cruz traded multiple messages, then spoke at length once on the phone and again in person, when Pence visited Capitol Hill a few weeks ago, a source close to Pence said.

Trump has hired key Cruz allies such as Kellyanne Conway as his campaign manager, and Jason Miller as a spokesman.

Wednesday, Trump's campaign expressed support for a Cruz-backed, Internet-related proposal in government funding talks in the Senate.

Friday, Trump released a new list of conservative judges likely to appeal to the former Supreme Court clerk -- including perhaps Cruz's closest friend in Congress, Utah Sen. Mike Lee.

Cruz cited Trump's pledges on the judiciary in his Facebook post. "We know, without a doubt, that every Clinton appointee would be a left-wing ideologue. Trump, in contrast, has promised to appoint justices 'in the mold of (the late Antonin) Scalia,' Cruz wrote. "For some time, I have been seeking greater specificity on this issue, and today the Trump campaign provided that, releasing a very strong list of potential Supreme Court nominees — including Sen. Mike Lee, who would make an extraordinary justice — and making an explicit commitment to nominate only from that list."

A Cruz endorsement could be the last pillar to helping Trump shore up the support of conservatives who have remained reticent about supporting his campaign.

Trump has already gotten most Republicans and conservatives on board with his campaign -- largely by reassuring them on the Supreme Court and on issues like the Second Amendment and abortion. But Cruz's principled opposition to offering his support has given some conservatives high-profile cover.

Just as Cruz's refusal to endorse Trump at the RNC fueled Democrats' efforts to paint Trump as divisive even within his own party, Cruz's endorsement will help undermine that narrative -- suggesting to conservatives unsure about Trump that perhaps the brash billionaire has changed, and can be trusted to bring conservative change to Washington.

'Lyin' Ted' and 'utterly amoral'

The move marks a dramatic turnaround from the personal insults Cruz and Trump traded during the previous year.

The two men clashed repeatedly during the primaries, as Trump taunted the senator with the nickname "Lyin' Ted," suggested Cruz wasn't eligible to be president due to his Canadian birthplace, and even speculated that Cruz's father was involved in the JFK assassination. Trump also said Cruz should "be careful" or he would " spill the beans on your wife ," and retweeted an unflattering picture of Heidi Cruz. Those tweets have not been deleted from Trump's account.

Lyin' Ted Cruz just used a picture of Melania from a G.Q. shoot in his ad. Be careful, Lyin' Ted, or I will spill the beans on your wife! — Donald J. Trump (@realDonaldTrump) March 23, 2016

On his last day of the GOP campaign -- the Indiana primary in early May -- Cruz let loose against Trump , calling the businessman a "serial philanderer," "utterly amoral," and "a narcissist at a level I don't think this country's ever seen.

At the RNC in Cleveland, Cruz gave a memorable speech espousing conservative values but ended without endorsing Trump, as Trump allies booed from the convention floor. "Don't stay home in November," Cruz said. "Stand and speak and vote your conscience."

The next day, he defended the move by citing Trump's attacks against his family.

"I'm not in the habit of supporting people who attack my wife and attack my father," Cruz told members of the Texas delegation . "That pledge was not a blanket commitment that if you go and slander and attack Heidi that I'm going to nonetheless come as a servile puppy dog and say, 'Thank you very much for maligning my wife and maligning my father.'"

After the convention, Trump said that he would not accept Cruz's endorsement if he offered it.

"I don't want his endorsement. If he gives it, I will not accept it, just so you understand. If he gives it I will -- I will not accept. It won't matter. Honestly he should've done it because nobody cares and he would've been in better shape for four years from now," Trump said.

Facing Senate primary in 2018?

Cruz's move may also be politically expedient. He faces a possible 2018 Senate primary challenge from Texas Rep. Michael McCaul, the chairman of the House Homeland Security Committee, who has increasingly made an issue of Cruz's failure to endorse Trump.

Republican National Committee Chairman Reince Priebus has said Republicans who don't back Trump could pay a price down the road. And Trump also floated the idea of setting up a super PAC to oppose Cruz if he decided to run for office again.

Clinton's campaign, after Cruz's message posted on Facebook, was happy to note a number of shots Cruz took at Trump during the primary, including when he called on the businessman to release his tax returns.

Clinton's official twitter account retweeted a tweet Cruz sent during the primary that said, "I've released 9 years of tax returns. RT if you agree it's time for Donald Trump to release his!"

I've released 9 years of tax returns. RT if you agree it's time for Donald Trump to release his! https://t.co/08whtFVC0r — Ted Cruz (@tedcruz) April 19, 2016

Clinton's campaign has been hounding Trump to release his taxes, arguing that he isn't doing so because they show shady business deals and ties to Russia. Trump has said he would release his taxes after an IRS audit.

Clinton's vice presidential nominee Tim Kaine, campaigning in Austin, Texas, Friday, said he couldn't support someone who used the same language Trump did about Cruz's father.

"I just can't help but say this," Kaine said. "Donald Trump suggested that Ted Cruz's dad was involved in the JFK assassination. Now we know that that is false, but false isn't, there's not the right word to describe what that is. It is so outrageously false. And as far as I know Donald Trump has not retracted it. As far as I know he has not apologized for it. And so if somebody said that about my dad they would never have me as a supporter for anything."

Radio host Steve Deace tweeted his disappointment, calling the move a mistake and speculating that Cruz backers may not all follow the senator.

"I think it's the worst political miscalculation of my lifetime. I hope I am wrong. The people will decide that," Deace tweeted.