The alerts you are receiving are NOT coming from Apple nor the macOS. They are most likely pop-ups coming from websites you are visiting through your browser. They are a scam designed to instill fear and separate you from you money by enticing you to purchase unneeded protection for your device.
Close the pop-up windows and disable them in your browser settings. You can allow pop-ups at any of your trusted websites via the same settings.
Please see: Allow or block pop-ups in Safari on Mac - Apple Support
Also: Protect your Mac from malware - Apple Support
If you would like to give yourself some peace of mind, you can download and run Malwarebytes.
The application scans for adware and malware and is a popular tool among veteran users here in the Community. See if it can identify any malware you may have accidentally installed. The free version is probably all you need at this point to identify and quarantine potential problems.