Just two months ago, Ted Cruz suggested that if he endorsed Donald Trump, he would be "a servile puppy dog."

But now he’s finally come around. "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 Friday afternoon about the man who memorably dubbed him "Lyin' Ted."

The endorsement emphasized that Cruz and Trump are simply closer on the issues — from Supreme Court appointments, to repealing Obamacare, to stopping what Cruz called "the deluge of unvetted refugees."

Plus, he argued that Hillary Clinton is simply unacceptable. "If Clinton wins, we know — with 100% certainty — that she would deliver on her left-wing promises, with devastating results for our country," Cruz wrote. "My conscience tells me I must do whatever I can to stop that."

Cruz, of course, spoke at the Republican convention in July but conspicuously refused to endorse Trump there, instead telling attendees, "Vote your conscience." Though Cruz eventually left the stage to a chorus of boos, it was an embarrassing moment for Trump, since it spotlighted his failure to unite the party.

But the move also caused big political problems for Cruz, who’s been sharply criticized by many leading conservative donors and activists. And Republicans in Texas weren’t too thrilled either — more than half of Texas Republican voters said they viewed Cruz less favorably because of it, according to one recent poll.

Two political reasons for Cruz’s flip-flop: He’s facing a potential primary challenge, and the Trump-Clinton race now looks close

Furthermore, since Cruz made such a big splash in July, two big developments may have helped convince him that his current course was untenable.

First, a potential primary challenge against Cruz by Rep. Michael McCaul has started to take shape. Cruz’s political strategy has always involved ensuring that he’s in tune with the conservative grassroots base, so he can easily win primaries. But in refusing to endorse Trump, Cruz has finally made himself vulnerable with that base.

Interestingly, though, McCaul doesn’t come from the Trumpist far right — he’s a multimillionaire GOP congressman who "is very well-networked within the donor class" in Texas, as a source put it to CNN. Essentially, the party establishment that has long loathed Cruz finally thinks they’ve found a way to turn the conservative base against him. (Earlier this week, McCaul said Cruz "broke his word" by refusing to back Trump, which is ... true enough, since he did sign a pledge to support the nominee.)

The second major recent development is that the presidential race now looks closer, which could change Cruz’s political calculation.

Back in the summer, it seemed that a Hillary Clinton landslide victory was a distinct possibility. And if that still looked to be the case, Cruz’s rejection of Trump would have looked prescient when he lost big. As Dara Lind wrote at the time, Cruz’s move seemed to be a bet that Trump would lose disastrously, and that Cruz himself would be positioned to pick up the pieces from that failure in 2020.

But if Trump instead loses in a squeaker, that’s terrible for Cruz — because he could be blamed for the defeat. A narrative that Trump was "stabbed in the back" would likely be pushed by his supporters in the conservative media, and Cruz would be one of the primary targets for recriminations.

The bigger picture, though, is that Cruz has simply never been comfortable defying the conservative base, and may have miscalculated just how furious people would be at him. According to National Review’s Eliana Johnson and Tim Alberta, Cruz later claimed he hoped his convention speech would be interpreted as a defense of conservative principles, albeit delivered with statesmanlike neutrality. Instead, it was interpreted as a stick in the eye to Trump.

Cruz was unwilling to keep criticizing Trump, which undermined his own position

Cruz also may have blundered by focusing on the personal aspect of his non-endorsement rather than framing it in terms of principle. "I am not in the habit of supporting people who attack my wife and attack my father," Cruz angrily said the day after his convention speech. He was referring to Trump’s efforts to falsely tie Cruz’s father to JFK’s assassination, and Trump’s threat to "spill the beans" on Cruz’s wife Heidi (complete with retweeting an unflattering picture of her).

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

Cruz continued: "That pledge was not a blanket commitment that if you go ahead and attack Heidi that I’m going to come like a servile puppy dog and say, ‘Thank you very much for maligning my wife and maligning my father.’"

But with an open Supreme Court seat at stake, and the potential for a Hillary Clinton presidency to advance all sorts of policies that conservatives loathe, Cruz’s focus on personal grudges came off as petty to many on the right. Indeed, as Cruz’s endorsement makes clear, he is genuinely closer to Trump on policy.

Now, if Cruz had proven willing to keep attacking Trump as personally unfit for the office of the presidency, his reservations would have seemed to make more sense. Then he could have forthrightly made the case that despite the fact that he’s closer to Trump on policy, Trump should be denied the office regardless.

But silence coupled with "he was mean to my family" wasn’t tenable. This was "a time for choosing," to borrow a phrase from Cruz’s idol Ronald Reagan. Now Cruz finally seems ready to make his choice.

This article was updated with news of Cruz's endorsement.