Try to restart the iMac in Safe mode. If this is a problem with graphic driver software, that might resolve the issue. If it does, then you're lucky.
See if the problem continues to happen in Safe mode.
Restart your iMac and press and hold the shift-key when you hear the chime. Hold until you see the Apple logo and progress bar.
How to restart in Safe Mode…
Use safe mode to isolate issues - Apple Support
NOTE– starting up in Safe mode could take 5-10 minutes. Be patient.
Does the problem persist while in Safe mode?
Restart your Mac again normally and re-evaluate the issue.
I hope your Time Machine (or other) backup is up to date.