Sen. Ted Cruz endorsed Donald Trump's presidential campaign on Friday, the latest chapter in a rocky relationship between the two men that has ricocheted from fawning support to searing personal insults to, now, a kind of detente.

In a Facebook message posted Friday, Cruz said he has had "areas of significant disagreement" with Trump, but cannot allow  Hillary Clinton to become president.

"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 said, noting he is honoring a commitment he made to endorse the Republican nominee -- something he stepped back from earlier this year.

The decision marks a politically risky move for Cruz, who pointedly refused to endorse Trump during a prime-time speech at the Republican National Convention in July. Cruz exhorted Republicans to "vote your conscience" and said he was standing on truth and principle -- ideologically pure stances Cruz espoused during his campaign and that could be imperiled with his endorsement of Trump.

Cruz was booed off the stage and his wife was filmed leaving early to avoid angry delegates. At a tense breakfast with the Texas delegation the following morning, Cruz said he wasn't going to "act like a servile puppy dog" and back Trump.

"No, this is not politics," Cruz said at the time. "I will tell the truth."

Ted Cruz was being loudly cheered by many of the delegates at the Republican National Convention on July 20 – until he urged voters to "vote their conscience." (Peter Stevenson, Sarah Parnass, Jorge Ribas, Alice Li, Dalton Bennett/The Washington Post)

The truth, Cruz said then, was that Trump had personally attacked his wife, Heidi, and father, Rafael. Citing an unfounded conspiracy theory, Trump repeatedly accused Rafael Cruz, who was born and raised in Cuba, of associating with Lee Harvey Oswald around the time of John F. Kennedy's assassination. Trump also retweeted an unflattering photo of Heidi Cruz contrasted with a photo of his wife, Melania, a retired model.

"I am not in the habit of supporting people who attack my wife and attack my father," Ted Cruz said in July. Previously, he said Trump was a "sniveling coward" who should "leave Heidi the hell alone."

In July, some delegates questioned how Cruz could turn back on a pledge he and other candidates made to support the Republican nominee.

"The day that was abrogated was the day this became personal," he said, adding he would never vote for Clinton.

Trump said after the convention he would not accept Cruz's endorsement if it were offered. In a statement Friday, Trump also reversed himself.

"I am greatly honored by the endorsement of Senator Cruz," the statement said. "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."

Even after making his impassioned pleas in Cleveland, Cruz's aides didn't rule out the possibility of an endorsement at a later date. Cruz had been facing growing pressure from donors to back Trump after staying on the sidelines since July. Cruz is facing a reelection fight in 2018, and talk had been mounting about a Republican primary challenge to Cruz -- chatter that may simmer down now that Cruz has endorsed Trump.

Over the past few days, the Texas Republican and his aides increasingly signaled that they were coming around to Trump. On Wednesday, Cruz thanked Trump on Twitter for backing his top legislative priority, a crusade on Internet domain names. Trump this week also said he would consider naming Sen. Mike Lee, one of Cruz's closest allies in the Senate, to the Supreme Court. Cruz's campaign manager, Jeff Roe, said at a Bloomberg Politics breakfast on Tuesday that Cruz's unwillingness to back a third-party candidate were limiting his options and that watching Trump run a "better campaign" has been "helpful."

The relationship between the two first turned vicious after Trump said Cruz's Canadian birthplace was a "very precarious" issue for the Republican Party and questioned his eligibility to run for president. Cruz has long said that he qualifies as a natural-born citizen because his mother was born in Delaware.

The two men spent months lobbing pointed insults at one another. Cruz called Trump a "pathological liar" who is "utterly amoral," a "serial philanderer," a "bully" and a "narcissist at a level I don't think this country has ever seen." Trump yoked Cruz with the nickname, "Lyin' Ted," and called him a "nasty guy," an "anchor baby," "unstable" and "sick."

It wasn't always this way.

At the beginning of the presidential race, the two men enjoyed a relationship that was unusually cozy for two ostensible rivals for the Republican presidential nomination -- a political buddy comedy movie of sorts. Cruz repeatedly lauded Trump as "terrific" and said he was happy the real estate mogul was in the presidential race. Cruz spent an afternoon at Trump Tower in Manhattan, and the two men headlined a Capitol Hill rally against the Iranian nuclear deal -- something virtually unheard of for two candidates running against one another.

In December, Cruz promised that nothing would come between him and Trump.

But it did, and now many conservatives and those in Cruz's orbit are dismayed that the candidate they saw taking a principled stance against Trump is now backing the businessman. Cruz is now back in the Senate, a body where he earned the enmity of his colleagues and wore it as a badge of honor. It was proof, Cruz said, of his outsider status, something that could be endangered with his endorsement of Trump.

"Another promising, talented politician is gonna learn the lesson of misspent political capital the hard way. Come quickly, Lord Jesus," Steve Deace, a prominent Iowa evangelical and Cruz supporter, wrote on Twitter.

Even some people who worked on Cruz's campaign rebuked their former boss.

Others are thrilled that Cruz is finally backing the nominee.

"I am pleased that he has done the right thing and it shows that he's really willing to help unite party," said Mica Mosbacher, who donated to Cruz and is now backing Trump.

Kellyanne Conway, who ran a constellation of super PACs backing Cruz and is now Trump's campaign manager, expressed her pleasure with Cruz's decision on Twitter.

A policy wonk who never shied from getting into the weeds of issues, Cruz laid out in detail six reasons why he believes Clinton cannot be president: the Supreme Court, Obamacare, energy, immigration, national security and Internet freedom. Cruz wrote that Trump's campaign has been "focusing more and more on freedom" over the past few weeks by emphasizing school choice and economic growth for Hispanic and African-Americans.

"Our country is in crisis. Hillary Clinton is manifestly unfit to be president, and her policies would harm millions of Americans. And Donald Trump is the only thing standing in her way," Cruz wrote.

Mike DeBonis, Paul Kane, Sean Sullivan and David Weigel contributed reporting.