LONDON — In a Europe struggling with a rise in Islamophobia, riven by debates about the flood of Syrian migrants and on edge over religious, ethnic and cultural disputes, London has elected its first Muslim mayor.

Sadiq Khan — a Labour Party leader, a former human rights lawyer and a son of a bus driver from Pakistan — was declared the winner after a protracted count that extended into Saturday. He will be the first Muslim to lead Britain’s capital.

The victory also makes him one of the most prominent Muslim politicians in the West.

London is hardly representative of Britain: About a quarter of its residents are foreign-born, and one-eighth are Muslim. And Mr. Khan is not the first Muslim to hold prominent office in Europe: Rotterdam, in the Netherlands, has had a Muslim mayor since 2009, and Sajid Javid is the British secretary of state for business.

Nonetheless, Mr. Khan, 45, won a striking victory after a campaign dominated by anxieties over religion and ethnicity. Britain has not sustained a large-scale terrorist attack since 2005, and its Muslim population, in contrast to France, is considered well integrated. But an estimated 800 people have left Britain to fight for or support the Islamic State. Dozens of assaults on British Muslims were reported after the Paris terrorist attacks in November.