One solution is to avoid the 4am boot
If everyone else is sleeping, your iMac can also be sleeping.
Wake it up at 4am, and it's not booting, just waking up. No chime.
That solution may not be good for you - if you are not comfortable with leaving your iMac sleeping, and you'll need a different solution involving muting through your system.
The boot chime is resident in hardware, and the operating system does not necessarily directly affect the boot chime.
However, if you press the mute key on your keyboard, then shut down, the boot chime should not sound on next boot. Some Macs will still chime, regardless of the mute, because the boot chime is hardware resident (depends on your Mac model) The boot chime is also (as you have discovered) independent of the hardware switches that normally mute the internal speaker when you have headphones, or some other external audio connected, so muting the boot chime mute may be tricky on some Macs.
Keep in mind, too, that "mute" depends on your other audio options: mute the main speakers, does not mute headphones. You can mute or unmute the headphones independently of the main speakers, and vice versa.