What model year is this 27" iMac? Check Apple Menu ➜ About This Mac.
Depending on that, will be whether you can upgrade to a newer macOS version or not.
No, you don't need a Mac mini, unless you want an entirely new computer. A Mac mini is not an upgrade for an existing computer. It's a whole computer in and of itself. It's like saying do I need to buy a new iMac to fix my old iMac.
You can buy any new keyboard and mouse if you want and use them with your existing computer.
As to the slowness, please post an etrecheck report of your current iMac and someone may be able to help you fix or at least reduce the slowness.
click here ➜ Using EtreCheck - Apple Community