An earthquake rocked western Afghanistan on Monday, killing more than 20 people and destroying hundreds of homes, local authorities said.