Sanders suffered a heart attack on Oct. 1, the first day of the fourth quarter. He resumed normal campaigning after his recovery. His campaign released doctors' notes this week saying he is fit to serve as president.

In a tweet Thursday, Sanders said "we're proving you don't need to beg the wealthy and powerful for campaign contributions in order to win elections."

The independent senator from Vermont and 2020 Democratic hopeful raised more than $18 million in December, his best month of the election cycle, his campaign said Thursday.

Bernie Sanders' presidential campaign shrugged off a health scare and took in more than $34.5 million in the fourth quarter, a massive haul in the final stretch before nominating contests start.

The total for the last three months of the year easily tops the money raised by Sanders' rivals who have announced their fundraising.

Former South Bend Mayor Pete Buttigieg took in $24.7 million during the quarter, his campaign announced Wednesday. Entrepreneur Andrew Yang's campaign raised $16.5 million in the last three months of the year, a major boost as he tries to catch his better known rivals.

Sanders' leading competitors for the Democratic nomination, former Vice President Joe Biden and Sen. Elizabeth Warren, D-Mass., have not yet announced their fundraising hauls.

It will take a lot for the eventual Democratic nominee to catch up to President Donald Trump in fundraising, however. The Trump campaign announced Thursday that it raised $46 million during the quarter. In the third quarter, Trump's campaign and the Republican National Committee pulled in a total of $125 million, which surpassed the $105 million second-quarter total.

Sanders' cash has likely left him with plenty of money to deploy ahead of the first nominating contests in Iowa and New Hampshire in February. The $34.5 million does not include $12.7 million in transfers from other Sanders campaign accounts.

The campaign did not immediately say how much it had in the bank at the end of the year. But it had $33.7 million on hand at the end of the third quarter, more than any of Sanders' rivals.

Sanders' campaign has seen a torrent of fundraising dollars from an army of individual donors. On Wednesday, it said it had received contributions from 5 million people during the election cycle.

The fundraising haul at the end of the year follows a $25.3 million intake from individual donors in the third quarter.

For the final three months of the year, Sanders donors most often listed their occupation as "teacher." The five most common employers of people who contributed to the campaign were Amazon, Starbucks, Walmart, the U.S. Postal Service and Target.

The senator routinely criticizes Amazon and Walmart for the pay and benefits they give workers.

Sanders trails only Biden in an average of national primary polls. He sits near the front of the pack in surveys of Iowa and New Hampshire.

Subscribe to CNBC on YouTube.