Broke plaster anchoring electrical box
There are plastic shims expressly for the purpose of supporting plugs and switches. They come in a strip and one tears off as many as needed and folds them accordion style and slips it over the screws to allow the switch to be screwed hard to the box parallel to the wall and the right distance from it.

Edit, Addition

In the present case, if I understand the querant's comment correctly, the box is loose in the wall. If he wants to avoid replacing this box, a clamp is required on both sides of the  to secure the box and the switch. The switch cover plate can supply the clamp onto the wall cavity side of the drywall (or plaster).

One such clamp is a pair of grip-lok sheet metal clamps. The grip-lok clamps could result in the box being positioned a little way back into the wall. If that happens then some of the spacers might also be required to get the switch positioned properly. But if the box ends up perfectly in the plane of the room side of the drywall, then no spacers would be required.