ISTANBUL — The Turkish government’s crackdown after a military coup attempt widened into a sweeping purge on Monday, cutting a swath through the security services and reaching deeply into the government bureaucracy and the political and business classes.

The sheer numbers being detained or dismissed were stunning: nearly 18,000 in all, including 6,000 members of the military, almost 9,000 police officers, as many as 3,000 judges, 30 governors and one-third of all generals and admirals, as well as President Recep Tayyip Erdogan’s own military attaché.

The magnitude of the backlash by Mr. Erdogan suggested that the depth of support for the coup was far greater than it initially appeared, or that the president was using the opportunity to root out all perceived adversaries, or both.

As hopes faded that Mr. Erdogan would try to use the moment to unite the country, instead taking a security-first approach, Western allies began to express alarm at what looked like score-settling. On Monday in Brussels, Secretary of State John Kerry and the European Union’s top diplomat, Federica Mogherini, urged Turkey — a member of NATO and a candidate for membership in the European Union — to show restraint and preserve the rule of law.