Self-organization of earthquake swarms