Shimano Hollowtech II cranks use two pinch bolts to secure the crank to the axle. From your picture it looks like you have those. You are missing the plastic end cap, and you may possibly be missing a washer that sits between the crank and the frame. There is no spacer, the play is probably because the crank arm is not fully on the spindle.
To install the crank you just slide the crank on the axle (you may need to drive it home with a mallet), hand tighten the end cap to set bearing preload (this is important!) then do up the pinch bolts to proper torque with a torque wrench.
Park Tool has a great article and video that shows you how these cranks go together: https://www.parktool.com/blog/repair-help/crank-removal-and-installation-two-piece-compression-slotted
However, you may have a serious issue. The crank slides on to splines on the axle, and should not be able to rotate even if the pinch bolts are loose. If your crank arm became loose and rotated 180 degrees the steel axle has likely significantly damaged the internal splines of the alloy arm. If this happens the crank will not stay tight on the axle and will work its way off again.
Update following more info and pics from OP:
The crank splines don't look too badly damaged, so I'd give re-installation a try. If the crank comes loose again then you'll want to replace it.
I checked the RS400 crank manual and there does not seem to be a washer between the arm and BB bearing. You need an end-cap obviously. Googling for 'Shimano Hollowtech stop bolt' yields end caps for various crank models, but not RS400, I think a basic plastic one will fit. A bike shop can help you get the right part of course.
Installation is straightforward but there are a couple of things that must be done right.
Setting bearing pre-load with the end cap. A special tool is needed The Shimano part is TL-FC16, they only cost US$5.
The pinch bolts must be done up simultaneously and to the correct torque, for which you need torque wrench.
You can do the basic assembly and get a bike shop to check it and use a torque wrench to do up the bolts.
If you end up replacing the crank Shimano RS400 cranks are relatively inexpensive (I once bought an older used set for US$35 on Ebay). However, what I would do is upgrade to a proper Tiagra crank to match the rest of the drivetrain (RS400 being a slightly lower level, and cheaper 'non-series' item).