You should be able to use the OS X Recovery feature to reinstall the OS from scratch. This will, however, not restore the lLife apps (like iPhoto, iMovie, etc) and you'll probably have to contact Apple (via the feedback tool in iTunes) in order for them to reassign those downloads to your AppleID, vs the AppleID of the person who originally purchased the Mac.
Here's an article with the basics about OS X Recovery.
http://support.apple.com/kb/HT4718
One thing you'll have to do that I didn't see mentioned is use the Disk Utility program to erase the hard drive, then reinstall OS X. Otherwise, OS X will just reinstall on top of the existing install, which won't erase what the previous owner had. You should see the Disk Utility program as an option when you restart your iMac in Recovery mode.
Good luck!