Bernie Sanders blazed across the Bay State yesterday, drawing record crowds, name-dropping Elizabeth Warren and greeting rapturous crowds on his first campaign tour of Massachusetts.

“As your senator, Elizabeth Warren, reminds us: This is a rigged economy. Heads, they win. Tails, you lose,” the self-avowed socialist told more than 20,000 Boston supporters. “We’re going to create an economy that works for the middle class and not just the 1 percent.”

The Democratic hopeful first stopped in Springfield, and then made his way to the Boston Convention & Exhibition Center, where he drew deafening cheers with his signature impassioned pledges to rebuild America’s middle class and fight for free college tuition.

Sanders, who has surged in recent months in polls versus front-runner Hillary Clinton, faces a steep road to the Democratic nomination — especially in Massachusetts, long a stronghold of support for the Clintons. The independent Vermont senator has campaigned on a platform of government-funded health care, college education and childcare — and taxes on the rich to pay for it.

Karen Higgins of National Nurses United, who introduced the Vermont senator at both events, told the crowds that although her organization would love to “break the glass ceiling” — referring to Clinton — “for now, we’d like to break the class ceiling.”

Playing to the student-heavy crowds in both locations, Sanders drew cheers as he discussed student loan forgiveness, an issue championed by Warren, and called for free tuition at all public universities.

“It is an expensive idea, about $70 billion a year,” he said. “We’re going to pay for that by a tax on Wall Street speculation.”

He added, “Today it’s Wall Street’s turn to bail out the middle class.”

He also took shots at the GOP presidential candidates for their criticisms of President Obama, saying his rivals “suffer from amnesia” and fail to acknowledge the tremendous national deficit and unemployment crisis during George W. Bush’s presidency.

“During this campaign we are going to rattle their amnesia and force them to acknowledge reality,” he said.

And he blasted the far right for using the term “family values” to oppose gay marriage and abortion.

“When I talk about family values,” he said, “what I talk about is ending the international embarrassment of the United States of America being the only country on earth that does not provide paid family and medical leave.”

Sanders also went beyond his usual talking points to address hot-button topics including gun control — one of the few issues on which the gun-owning candidate skews to the right of Clinton.

Sanders said Congress must pass legislation that closes gun show loopholes, and “says clearly guns should not be owned by people whole should not have them.”

The candidate, who drew fire in recent months from Black Lives Matter hecklers, also waded into the controversies surrounding law enforcement.

The United States “has a long way to go to overcome institutional racism,” he said, and “when a police office breaks the law, that officer must be held accountable.”

The crowds — among the largest of Sanders’ nationwide campaign — ate it up.

Victoria Yan, 18, a student at Mount Holyoke College who attended his Springfield rally, said Sanders was “inspiring” and exceeded her expectations.

“You go online and you see a lot of hype around him,” she said. “To see him in real life — it was an awesome moment.”