Not so long ago, Mr. Mamdani was a little-known state assemblyman. But his personality and platform captivated an unlikely coalition of New York City primary voters.

Mr. Mamdani is Muslim, and his faith played a role in expanding the diverse coalition that propelled his campaign.

Mamdani said his city would be one \