MANCHESTER, New Hampshire — Bernie Sanders, Congress’ longest-serving independent and a self-described socialist, backtracked just two days into his presidential campaign on Saturday, saying he would register as a Democrat if needed to compete in the party’s primary in all 50 states.

Announcing his candidacy Thursday outside the U.S. Capitol, the senator from Vermont rejected any suggestion that he register as a Democrat. “No,” Sanders said, “I’m an independent.” But a day later, questions surfaced in New Hampshire about whether he would be eligible to compete next year in the nation’s first presidential primary.

New Hampshire requires candidates to fill out a form declaring party registration. Sanders also rejected the Democratic nomination for Senate twice in Vermont, New Hampshire news media noted.

On Saturday, after addressing a mosh pit of more than 100 supporters stuffed in a Manchester home and spilling out into a yard, Sanders said: “We will do what we have to do” to make sure his name appears on the ballot alongside Hillary Rodham Clinton.

Sanders’ new openness to registering as a Democrat follows his campaign’s statement that he raised an impressive $1.5 million in the first 24 hours of his announcing: A grass-roots surge from 35,000 donors who gave an average of $43.54 apiece, the campaign reported.

Sanders stressed repeatedly Saturday that he is in the race to win it. Known in Washington as a pragmatic politician, his party affiliation appeared to be an early compromise, though he often sits with the Democratic caucus.

“We’re going to fulfill all the rules,” Sanders said, when asked about the potential roadblock. “You know, I am the longest-serving independent in congressional history. I made the decision that the best way to be effective in this campaign, the best way to win was to do it through the democratic primary process. We will meet all of the requirements of all of the states, including New Hampshire,” he said.

Even if that requires registering as a Democrat?

“We will do what we have to do. We are going to be on the ballot in 50 states. You don’t win unless you do that,” Sanders said.

In every other way, Sanders remained the idealist Saturday, acknowledging his long-shot campaign will rise or fall on an idealistic vision for bolstering the middle class.

Sanders said he wants a $1 trillion infrastructure campaign to create 13 million jobs. He said he will soon introduce legislation in the Senate for a $70 billion plan to make public colleges and universities tuition-free. He suggested funding for the plan could come from eliminating corporate tax loopholes that allow companies to keep profits overseas. And he said the nation needs to move toward a single-payer Medicaid system for health care and increase social security benefits.

“We are going to run a campaign unlike any before,” Sanders said. “I’m running because this country faces more serious crises than at any time since the Great Depression.”