Mr. Castro was outspoken when Senator Kamala Harris of California made a surprise exit from the race in early December, saying that “Kamala was treated very poorly” and had been “held to an unfair standard” by the media.

“The media’s flawed formula for “electability” has pushed aside women and candidates of color,” he said that day on Twitter. “Our party’s diversity is our strength.”

For some, Ms. Harris’s departure bolstered the case Mr. Castro had been making about the primary system. On the day she announced she was dropping out, Mr. Castro had his best fund-raising day of the quarter.

Mr. Castro’s concerns about the field’s diminishing diversity were amplified again in the days leading up to the December debate, when nine of the Democratic candidates signed a letter to the D.N.C. asking officials to lower the thresholds to qualify for the party’s January and February events. The letter noted that many of the candidates who had helped make the Democratic field diverse had been “excluded.” And indeed, the December debate featured six white candidates and only one person of color, the businessman Andrew Yang.

Shortly after Mr. Castro made his announcement, other candidates expressed their disappointment at his departure and gratitude for his contributions.

“Your voice and campaign were invaluable in sticking up for underrepresented communities and pushing the field forward,” said Senator Cory Booker of New Jersey, who later sent a fund-raising appeal to supporters directly invoking Mr. Castro and the racial makeup of the field.

Senator Elizabeth Warren of Massachusetts, speaking to reporters after a campaign event in Concord, N.H., praised Mr. Castro as “a firm, clear, moral voice in the primary” and said she was “very sorry” he was leaving the race.