WASHINGTON—Bernie Sanders doesn’t exercise in the U.S. Senate gym, where many of his colleagues hang out and forge friendships. He is more likely to have breakfast amid the interns in a basement cafeteria than in the formal Senate dining room. And the Vermont Independent is sometimes so focused on business that he often launches into phone conversations without even saying “hello.”

On the campaign trail, the 73-year-old who is running for president as a Democrat, is attracting large, cheering crowds drawn by his unabashedly liberal positions on Wall Street, taxes and government spending. Inside the Capitol, where he’s served for more than 20 years, he cuts a different figure—a distant and quirky lawmaker whose legislative record is mostly made up of modest wins captured through compromise.

In 2010, he and other Democrats inserted money for community health centers into President Barack Obama’s signature health law—a boon for Vermont—despite Mr. Sanders’s preference for an alternative health system. He tucked language into the 2010 Dodd-Frank financial regulation law that allowed for an audit of the Federal Reserve’s response to the financial crisis, although he had wanted to subject the central bank to routine audits.

Earlier, he went on an amendment spree in the House, using the process to secure money for home-weatherization assistance, aid to older Americans, and so many other projects that even the House Appropriations Committee chairman at the time took note. “Bernie had a good instinct for knowing what people would like to vote for,” recalled former Rep. David Obey (D., Wis.) in an interview.

“To suggest that I cannot work with people who disagree with me would be pretty absurd,” Mr. Sanders said in a telephone interview when asked about his legislative record.