A picture of your setup would help. Off the top of my head, these clamps (available in different lengths) should let you clamp the iMac’s foot down to the desk (possibly with a riser).
https://www.amazon.com/IRWINQUICK-GRIPOne-Handed-Mini-Clamp-Pack-1964748/dp/B00TKIUL84