Rep. Alexandria Ocasio-Cortez endorsed Sen. Bernie Sanders' presidential campaign as he was hospitalized in Nevada following a heart attack.

But the freshman congresswoman was torn for months between her allegiance to Sanders' political revolution and her respect for Sen. Elizabeth Warren's achievements in Washington.

Sanders invited Ocasio-Cortez to Burlington, VT last month to ask for her "strategic guidance," Sanders' campaign manager Faiz Shakir told Insider. That was the turning point for the congresswoman.

Three days later, Sanders had a heart attack. So Ocasio-Cortez decided to speed up her timeline.

Visit Business Insider's homepage for more stories.

When Sen. Bernie Sanders was asked during last Tuesday's Democratic debate how he can reassure voters he's physically prepared for the presidency, he touted his upcoming rally in Queens and a "special guest" who'd be joining him there.

In the closing minutes of the debate, news broke of Rep. Alexandria Ocasio-Cortez's imminent endorsement, along with expected endorsements from her fellow freshman lawmakers, Reps. Ilhan Omar and Rashida Tlaib.

With the support of three-fourths of the so-called "Squad," the Sanders campaign heads into the final stage of the primary season riding a wave of youthful progressivism that could be key to snagging the nomination. But this wasn't always a certainty.

When Sanders announced his 2020 presidential bid last February, Ocasio-Cortez hadn't yet decided if she'd endorse him.

Even after volunteering for Sanders' campaign in 2016, the freshman congresswoman from New York was torn between her allegiance to his political revolution and her respect for Sen. Elizabeth Warren's achievements in Washington.

"She liked both candidates," a source close to Ocasio-Cortez told Insider. "For months she was saying, 'Ah, I don't know. I like both.' She wasn't being coy, she wasn't being flip. She was just seriously saying, 'I don't know.'"

But then Sanders invited Ocasio-Cortez to Burlington, VT, last month to ask for her "strategic guidance," Sanders' campaign manager Faiz Shakir told Insider.

A previously unreported dinner on September 27 and a breakfast at a local diner with Sanders the next morning convinced the Bronx native that she'd eventually go all-in for her fellow democratic socialist.

Read more: Alexandria Ocasio-Cortez's endorsement of Bernie Sanders is a huge win for him and a way for her to hit back at the Democratic Party

"From there things kind of took off," Shakir said. "We had a lot of private conversations about the vision of how to win."

Then, three days later, Sanders had a heart attack.

Preparing to call him at the hospital to wish him well, Ocasio-Cortez decided she wanted to give his campaign a real shot in the arm.

"Her reaction was that this is ... when he needs an injection of energy in the campaign and she thought, 'If I have any capacity to do that, I should try,'" the person close to her said.

"It took an incredible amount of courage on her part to call in that moment and lend support," Shakir said.

After that, the two teams decided to unveil Ocasio-Cortez's endorsement at a rally in Queens on Saturday titled "Bernie's Back."

Shakir said the Sanders team worked with Ocasio-Cortez and Omar to pick the most strategic moment for a boost.

"We're at quarter four of the year and quarter four of the fundraising cycle and this is when I think you want to be cresting," he said.

He added that it's paying off for the campaign. "It is certainly putting wind at our backs at the right time in the campaign."

The source close to the campaign said they expect Ocasio-Cortez to go out on the campaign trail for Sanders in several early primary states and Super Tuesday states, including California. Shakir said his team is working with the congresswoman to organize a campaign event in Iowa in "the near future."

While Tlaib hasn't announced her endorsement yet, Shakir said Sanders is planning to visit the Michigan lawmaker in Detroit later this month for events that will focus on affordable housing issues.

Locking down Ocasio-Cortez's support at such a critical moment has Sanders supporters elated.

"I don't think a hospitalization is good for any campaign," Alexandra Rojas, the executive director of Justice Democrats, told Insider. "To have an endorsement right now [says] that this campaign that Bernie is running is important to progressives and to our movement."

Read more: Alexandria Ocasio-Cortez is endorsing Bernie Sanders this weekend, and polling shows that's a big hit to Elizabeth Warren

Rojas' organization, which helped power Ocasio-Cortez's 2018 primary campaign, has voiced support for both Warren and Sanders, but hasn't endorsed any candidate for president.

Sanders' and Ocasio-Cortez's teams say the two lawmakers have developed a strong personal rapport. The source close to the congresswoman said the two built "amazing chemistry" beginning on the campaign trail last year in Kansas and Michigan where they took "four-, five-, six-hour car rides" between events.

"They're ideological compatriots. They see and understand one another," Shakir said. "Both of them have this experience of shaking up the Democratic establishment and sometimes earning the ire of the Democratic establishment and it bonds them to some degree."

Rep. Alexandria Ocasio-Cortez and Sen. Bernie Sanders at a press conference in Washington. Saul Loeb/Getty Images

The Warren-Bernie primary

The unexpected endorsement news is a blow to Warren. The Massachusetts senator had been building a relationship with Ocasio-Cortez for months, lunching in Washington and collaborating on the Hill, including on legislation targeting private prisons and an effort to investigate Treasury Secretary Steve Mnuchin.

After the debate, Warren told reporters she has "great respect" for the three congresswomen and that "when this primary is over, we are all going to be on the same side."

Some argue Ocasio-Cortez's support will make Sanders feel less vulnerable to Warren. With a boost from the progressive star, the urgency to attack the senator will diminish.

"Warren is the frontrunner and entering the scrutiny phase, so there will be lots of attacks against her," a Democratic strategist, who wished to remain anonymous to speak candidly, told Insider. "The worst thing in the scrutiny phase is Bernie being weak."

Ocasio-Cortez is also wary of becoming a source of division as Warren and Sanders battle for the progressive vote.

"It's important that she doesn't divide with rhetoric," the source close to her said.