Democratic 2020 U.S. presidential candidate and Senator Bernie Sanders (I-VT) marches in the Nashua Pride Parade in Nashua, New Hampshire, June 29, 2019.

Sen. Bernie Sanders raised $18 million in the second quarter, a haul that trails at least one of his rivals in the 2020 Democratic presidential primary.

The Vermont independent took in $24 million during the period, including $6 million transferred from other committees, his campaign said Tuesday. It ended June with about $30 million on hand, a campaign spokeswoman said.

Sanders has aimed to build a cash pile from small-dollar donors as he tries to set himself apart in a field of about two dozen Democratic primary candidates. As contenders compete for a limited pool of donors, Sanders and several rivals have sworn off wealthy donors and expensive fundraisers.

The self-described democratic socialist fell short of at least one of his rivals in the second quarter. South Bend Mayor Pete Buttigieg's campaign said it raised $24.8 million during the period. Other leading candidates have not yet released their fundraising totals.

Sanders' campaign argued Buttigieg brought in more because Sanders relies on small contributions rather than major donors.

"Bernie Sanders does not go into closed-door, high-dollar fundraisers and solicit money from corporate executives at their homes," his campaign manager Faiz Shakir told CBS News on Monday.

Ed O'Keefe tweet: JUST IN: @BernieSanders campaign manager @fshakir tells @CBSNews he thinks Buttigieg "probably will have more money raised than we will" in Q2 b/c the mayor "solicits money from corporate executives from their homes" unlike Sanders who focuses on small $$ donations. #Roadto2020

The Sanders campaign touted grassroots support for the senator on Tuesday. More than 99% of donations were $100 or less, it said. It added that donors gave an average of $18 and said it took in nearly 1 million donations.

Sanders' fundraising stayed about flat since the first quarter, when his campaign raised $18.2 million. Out of the second-quarter donors, 46% gave for the first time, according to a campaign spokeswoman.

Competing with a jammed Democratic field for money, candidates who hope to challenge President Donald Trump next year have so far trailed the incumbent in the money race. The president's campaign and joint fundraising committees with the Republican National Committee raised $54 million in the second quarter. The Trump campaign finished June with $56 million on hand.

Sanders, 77, has garnered about 17% of support in an average of early national primary surveys, according to RealClearPolitics. While he trails only former Vice President Joe Biden by that metric, rivals Sen. Elizabeth Warren, D-Mass., and Sen. Kamala Harris, D-Calif, have recently gained ground.

— CNBC's Brian Schwartz contributed to this report

Subscribe to CNBC on YouTube.