Contact Apple if you have an Apple store nearby. Take the serial number with you if you can't take the Mac along.
Some iMacs were part of a graphics recall, these are normally listed at…
https://www.apple.com/support/exchange_repair/ but Apple remove older programs as they expire - sometimes a genius will take sympathy on you & offer help if it was under a repair program.
Other options are to try to see if you can isolate the issue yourself…
Try safe mode if your Mac doesn't finish starting up - Apple Support
Limited graphics performance in OS X recovery or safe mode - Apple Support
See if some basic resets alter it…
How to Reset NVRAM on your Mac - Apple Support
Resetting the System Management Controller (SMC) on your Mac - Apple Support
This may not detect all errors, but it is worth a try - sometimes it gives you an error code to look for more info.
Using Apple Hardware Test - Apple Support
Run normal & extended tests, for several iterations, hit cmd+L to enter loop mode for easy unattended testing.