Macs do not get viruses. What you have sounds like a pop-up and can be removed easily.
Force Quit Safari ( command + option + esc keys).Then restart Safari holding the Shift key. If you still have problems Empty Caches (Safari menu > Preferences > Privacy > Remove all website data. (This will also remove history if you do not want to remove History open Safari Preferences > Advanced and check mark “Show Develop Menu” then choose “Empty Caches” from Develop Menu ).
Then go to Safari Preferences > Extensions and check there. If there is an extension delete it.
If the problem persists then download and run Malwarebytes. There is a free download. Malwarebytes was developed by one of our own colleagues here in ASC and is about the most proven anti-malware software for Mac.