The mayor-elect barely cleared 50 percent of the vote in a race that stoked deep divisions along religious and class lines.