What went wrong? Absolutely nothing. Why is it that beekeepers think something went wrong when a hive is healthy enough to swarm? Weak, sick hives do not swarm. Healthy populated ones do!
What can you do to prevent this? Absolutely nothing! There are things you can do to lower your swarming rate, like use first year queens, expand and keep adequate room for the queen (Notice I said for the QUEEN...which is different than having a bunch of empty boxes on top), use entrances above the excluder, among other things. I've seen five frames of bees in a ten frame box swarm after a few weeks after starting from a package.
Anyone telling you they can stop swarming due to a type box, type of queen, or some management "trick" is full of themselves. So lets get through that first. Then you should move onto learning what you can do about swarms in lowering the rates of swarming.
FLOW dictates much more swarming than about anything else. Bees are programmed to perpetuate their species in times of nectar production. Insects being insects, and if you know what a bell-curve is, than you will always have the oddball swarm at odd times. But you probably still have some sort of flow happening, or these bees just got a late jump on the swarming season.
Remember swarming is the hives way of superceding the queen. Nature dictates that almost all hives requeen themselves every year. They seek out young queens and play the best odds in their favor.
We can fool some of the hives some of the time, but can not fool all the hives all the time.
Losing or having a swarm is no indication of one's beekeeping skills or knowledge.