“It’s important to keep a leader, a fighter, and warrior like Mike Capuano around,” Mr. Lewis said at the event, which was equal parts gospel service and political town hall and held at the same Massachusetts church where the Rev. Martin Luther King Jr. once served as an assistant pastor in the 1950s.

His argument is emblematic of the bitter intraparty debates that Democrats are having across the country ahead of the 2018 midterm elections — debates that often split liberals across the touchy fault lines of race, age and gender. The campaign appearance by Mr. Lewis and the recent decision by the political arm of the Congressional Black Caucus to back Mr. Capuano has made this primary race a microcosm of a larger search for identity among Democrats, while igniting friction between national black politicians and local ones.

The Seventh Congressional District that is up for grabs stretches from Boston’s Dorchester and Roxbury neighborhoods to the communities of Cambridge and Somerville across the Charles River. It is the state’s only district where the majority of residents are not white and Mr. Capuano, who is white, has never faced a serious primary challenger in his 10-term tenure in Congress.

Then came the bid by Ms. Pressley, who was the first woman of color to be elected to the City Council in its 108-year history. But instead of rallying around her, high-profile black politicians — including Mr. Lewis, Representative Maxine Waters of California and former Gov. Deval Patrick of Massachusetts — have all endorsed her white opponent.

Mr. Lewis declined several requests to discuss his endorsement. Representative Gregory W. Meeks of New York, the chairman of the black caucus’s political action committee, said the group endorsed Mr. Capuano largely because of his longtime personal relationships with its members and his senior position on the House Financial Services Committee.