Water changes. just make sure to treat new water with Prime or some other dechlor that covers chlorine and chloramines.
As for how it happened, it could have been a number of things. Did you stir up the substrate? Are you sure the tank was cycled beforehand (no ammonia or nitrite readings)? Did you rinse out the filter media? Are you treating with any chemicals at all? Did a lot of decaying organic matter suddenly get introduced (big die-off)? Did you add a lot of fish at once?
Check for ammonia, too.