The thing which holds it all together are the pinch bolts on the stem.
Unintuitively:
- loosen the pinch bolts on the stem
- tighten the preload on the top cap (make sure the top cap isn't running into the steerer tube -- the top of the spacers should be above the steerer tube; typically you move spaces from below to above the stem, or vice versa, unless you want to saw your steerer tube), until it's no longer loose
- tighten the pinch bolts on the stem[*]
[*] I believe at this point, it should no longer matter what you do with the top cap, or the spacers above the stem, though some sources will tell you to leave it tightened.