There is a PRAM setting you can apply that when used on laptops will prevent the internal display from working when an external is attached. It may work the same on an iMac, but there's no guarantee. To do this, open the Terminal utility and run the following command:
sudo nvram boot-args="iog=0x0"
Provide your password when prompted, and then restart your Mac to see if this does what you want. If not then you can revert it either by resetting the PRAM on your system (reboot with the Option-Command-P-R keys held immediately after hearing the boot chimes, and release them when the system resets and sounds the boot chimes again), or by running the following command at the Terminal and then restarting again:
sudo nvram boot-args=""