That fifteen (!) year old iMac wants to retire. You should let it.
It needs service, likely for a bad power supply or failing display components. Unfortunately, Apple and most Apple Authorized Service Providers won't touch it because it is long obsolete and new replacement parts are not to be had.
I hope you have been making regular backups using Time Machine or other means. If you have not, then your options are: 1) connect that iMac to another Mac and hope you can access the internal drive using target disk mode. Transfer files between two Mac computers using target disk mode - Apple Support
Or 2) pull the internal drive from that iMac and connect it to another Mac using an external drive enclosure or drive adapter cable.
Either way, it's time to replace that iMac with something newer.
Tip: never purchase a used Mac from a private party. If the previous owner does not prep the Mac by following the guidance here – What to do before you sell, give away, trade in, or recycle your Mac - Apple Support – then you could be buying nothing more than a door stop. Buy only from reputable Mac resellers.
This may be a good place to start: Certified Refurbished Products - Apple