Zohran Mamdani has won the closely contested New York City mayoral election, becoming the first Muslim to lead the largest city in the United States, media reports said Wednesday.