First check whether you need a spacer behind the cassette itself, or that the whole freehub is loose on the hub, like the others said. Bike shops will have the necessary spacer if that's the problem. If the freehub is loose on the hub shell, tighten it firmly to the shell with a 10mm hex key after removing the axle.
If the freehub's own internal bearing adjustment has loosened, you can remedy that by removing the axle, removing the dustcap on the freehub, inserting a Shimano TL-FH40 tool, and tightening down the bearing race firmly (it's reverse-thread, so lefty-tighty). It's not very common for this to happen, but I do see it once or twice a year.