Cause and effect points to out-of-spec memory.
Run Apple Hardware Test. Run the extended tests.
Using Apple Hardware Test
If it fails the memory tests, remove the memory and re-seat it. The sockets are very "tight". Run AHT again.
If it still fails, replace your original memory. If it works, you found the problem. Buy Mac memory from Crucial or OWC / MacSales.
May not be the same issue but could be related, but there is a long thread here about problems after installing 16gb of RAM:
Seems that iMacs a very picky about the make of RAM installed. A workaround is to drop down to 12gb with the proper solution being to only install certain makes of RAM - Samsung being one plus one or two others. Worth a read through the thread.
Seems that iMacs a very picky about the make of RAM installed.
Just bear in mind that thread concerns the 27" model. I only read a few pages but could find no specific references to the 21.5" model.
16 GB should not be a problem in a 21.5" iMac. I have the exact same mid-2011 model as the OP and am using 16 GB memory from Crucial. Prior to installing it I tried a 16 GB Kingston memory kit, which resulted in problems similar to those described in that thread.