Update: nothing I tried fixed the problem, and then the graphics card went out completely. After putting it in storage for months I finally decided to try a new graphics card (or rather a used one from eBay, but new to me) and it worked... perfectly... and four months later still haven't had any issues. For many this may have other causes but in my case it appears to have been a faulty graphics card. By now I have a closet full of iMac parts I tried to fix it with, but at least it works now.
Hope this helps, and good luck :)