In addition to @WheelieNick's excellent advice, I would like to add that you probably should perform a clean install of macOS by first erasing the drive before reinstalling macOS. If you have a 2018+ Mac, then you can instead perform a firmware "Restore" which resets the security enclave, firmware, and prepares the internal SSD for installation of macOS. With an Apple Silicon Mac, the firmware "Restore" process will also push a clean copy of macOS onto the internal SSD, while with an Intel Mac you will need to use Internet Recovery Mode to reinstall macOS.
How to reinstall macOS - Apple Support --- see the "erase disk" link in that article as well
Revive or restore an Intel-based Mac using Apple Configurator - Apple Support
Revive or restore an Intel-based Mac using Apple Configurator - Apple Support
Either process will give you a factory fresh OS on your computer as long as you do not restore from a backup since the backup may include malware. It may be possible to manually pull important files from the backup, but it can be tedious & time consuming and you still must be careful so as not to bring the malware back to the clean system. You may need to contact a professional to assist you with this process....especially for accessing the data from a backup.
You should also review this excellent article written by a respected forum contributor on how to keep your Mac safe by practicing safe computing habits which will help keep your Mac running smoothly and minimize the chances of acquiring malware or having your accounts hacked (article contains links to other articles for these items as well).
Effective defenses against malware and other threats - Apple Community