ANKARA, Turkey — Turkey’s president on Wednesday declared a three-month state of emergency following a botched coup attempt, declaring he would rid the military of the “virus” of subversion and giving the government sweeping powers to expand a crackdown that has already included mass arrests and the closure of hundreds of schools.

President Recep Tayyip Erdogan, who was accused of autocratic conduct before the insurrection, said the measure would counter threats to Turkish democracy. Possibly anticipating investor jitters, Erdogan criticized Standard & Poor’s for downgrading its credit rating for Turkey deeper into “junk” status and said the country would remain financially disciplined.

The president did not announce details, but the security measure could facilitate longer detentions for many of the nearly 10,000 people who have been rounded up since loyalist security forces and protesters quashed the rebellion that started Friday night and was over by Saturday.

“This measure is in no way against democracy, the law and freedoms,” Erdogan said in a national televised address after a meeting with Cabinet ministers and security advisers.

The state of emergency announcement needs to be published in a state gazette and lawmakers have to approve it for it to take effect, according to analysts.