Follow these instructions:
In addition to the above:
- If you enabled FileVault, disable it in System Preferences > Security & Privacy.
- "Deauthorize" your iTunes account. Same for Audible if you have one.
- System Preferences > iCloud > de-select "Back to My Mac" and "Find my Mac".
- Sign out of iCloud. Select "Delete from Mac" when it appears.
- Start your Mac with its original System Installation DVD (if your Mac shipped with one) or OS X Recovery (if it didn’t).
- Remove any Open Firmware password if you created one: select Firmware Password Utility from the Utilities menu and remove it.
- Select Disk Utility from the Utilities menu.
- Remove any partitions you may have created.
- Select the Mac's hard disk icon, then select the "Erase" tab.
- Select the "Security Options" button and erase the disk.
The more "securely" you erase the disk, the longer it will take. The fastest method is sufficient since all but the most expensive techniques and equipment will be able to recover securely erased data.
- When it finishes, quit Disk Utility.
- Select Install Mac OS X from the Utilities menu. Do not create any user accounts.
- When it finishes, shut down the computer.
- If you want to install the bundled apps that were included with your Mac, restart by using your Applications DVD and install the bundled apps.
- Applicable to selling outside your family or others close to you: Don't forget to include any DVDs that came with your iMac, your AppleCare certificate if you bought it, printed documentation, even the box if you still have it.
- Execute a bill of sale showing the Mac's serial number.
- Once no longer in your possesion, remove the Mac from your devices in My Support Profile.