Shares of Twitter Inc. and Facebook Inc. endured a surprise rout this week, as investors were rattled by signs that users are souring on the social-media stalwarts.

Twitter said Friday that its number of monthly users dropped in the second quarter and could continue to fall as it purges fake accounts, results that echoed Facebook’s bombshell guidance Wednesday that its growth is expected to slow through the end of the year.

Both...