Yes.
The main concern is if the motherboard can support the CPU. Even though it is the same socket there are some CPUs that may not work if Apple didn't program in support for them on the motherboard. (In the PC world as new CPUs come out the motherboard companies will release software updates that enable the new CPUs to be used. Apple doesn't do that because they aren't built to be upgraded after the fact.)
You can see here that the three CPUs that can come installed in the iMac are the I5-6500, I5-6600, and I7-6700k. Those will work for sure. The first is likely what you already have, and the second isn't much of an upgrade, so that leaves the i7-6700k that you would like to install. It is possible, but mattwithcats does brings up a legitimate concern regarding the TDP. While officially supported the 6700k does put off more heat. I have seen youtube videos showing that the 6700k in the iMac does 'thermal throttle', meaning it doesn't run as fast as the box says because it gets too hot, so don't expect as much as a boost as you thought you would get. Still a worthwhile upgrade overall but maybe not as much as you hoped.
On that note, you should consider whether or not you should upgrade, and that depends on what you want it for. If you want better gaming performance then you may not get much, since the GPU will be the greater bottleneck there. If you want to do video editing or something else that can benefit from HT (HyperThreading) on the 6700k then that would be worth the upgrade. But in my opinion it isn't worth the trouble for just a few more hertz if you aren't going to use any programs that will actually get any boost from the HT.
It would be better to get an i5 that is cheaper than the i7, but better than the i5 you currently have. That would give you performance boosts in everything you already do with your current i5 and wouldn't thermal throttle either. However, by installing a CPU that isn't officially supported by Apple (one of the three listed above) it may not work, so it would be a gamble. I haven't found any indication that someone else has taken the gamble with any other CPU so if you do decide to try a different CPU there is no guarantee it will work (but there is no guarantee that it won't either!).