Rep. Alexandria Ocasio-Cortez agonized for months over which lefty Democrat to endorse for president — but it was Sen. Bernie Sanders’ recent heart attack that pushed her into his camp.

“Her reaction was … he needs an injection of energy in the campaign,” a source close to her told Business Insider.

AOC will announce her formal endorsement of Sanders at a “Bernie’s Back” rally in Queens Saturday.

She was a Sanders volunteer during his 2016 presidential campaign, but considered throwing her support to Sen. Elizabeth Warren — the socialist’s nearest ideological rival in the 2020 field.

But Sanders wooed her aggressively, inviting her to Vermont last month to request her “strategic guidance” and taking her out to breakfast at a local diner.

Sanders has been slipping in the polls in recent weeks as Warren has surged.