Those are not interchangeable.
In the pre-Intel Mac days, modules slightly faster than those specified for a particular model could "clock back" and sometimes work in an older Mac with a slower system bus. Example: many PowerPC Macs (pre-2006) with PC-100 system buses would work fine—but no faster—with PC-133 RAM. That was a LONG time ago in a galaxy far....
That has not been a viable thing since the advent of Intel Macs in 2006. Intel Macs require the RAM speed Apple specs call out. Yours is Intel.
If you have 12GB now, I wager that you are not stressing it at all on that computer. I used as 2010 iMac with 12GB RAM for years and it never showed memory starvation. This is an Actvity Monitor screenshot I kept from that 2010 model:

Yes, at first it looks bad, but read on...
Starting with macOS 10.9 (2013), Apple changed its memory management strategy to one that makes better use of what RAM is present. "Memory Used" was not longer the operative metric for Mac RAM evaluation.
The new metrics became Memory Pressure and Swap Used. Pressure should be in the green and Swap should be well under 500MB. Note in the screenshot that almost all the memory was "used," but Pressure is as low as Activity Monitor can display, and Swap is zero. At the time of the screenshot, the computer was runnig 100% happy and fully functional.
If your 2009 iMac feels slow, I feel certain it is either the obsolete Core 2 Duo processor or, more likely, a slow mechanical hard drive. That model has a slower SATA drive bus than was used in 2011 and newer iMacs. Best expected data transfer for the stock drives Apple used then is about 90-110MB/sec. Even if you endured the pain of installing an internal solid-state drive upgrade, your max possible speed on that SATA 3GB data bus is about 250MB/sec.
For comparison, drive scores I've seen for current iMacs are sitting at 3000MB/sec and up.
This Apple article shows how to use Activity Monitor to evaluate memory usage:
View memory usage in Activity Monitor on Mac - Apple Support
Swap is a measure of Virual memory use. If Swap gets to more than about 500GB, you don't need RAM. A simple restart returns it to zero.