Hi and Welcome. My Name is ***** ***** I look forward to assisting you today with your question.
The only way to get in back to your iMac is by using a USB keyboard or a 2.5 GHZ wireless keyboard (not bluetooth) if the bluetooth keyboard is not working. All you have to do is, plug in the USB keyboard and it will allow you to type in the password (it doesn't require any setup). After logging in, you can pair the bluetooth keyboard from System Preferences > Bluetooth.
Is the Logitech keyboard wired or wireless one ? Please let me know by replying in here.