A Safari page claiming 'Apple Security Warning', 'your Mac has been infected with viruses', or 'your Apple ID will be locked' — often with a number to call — is a scam page. Apple does not detect viruses on your Mac through a website, does not lock screens with warnings, and does not publish support phone numbers in pop-ups. The page is theatre; closing it is the whole fix in almost every case.
Cmd+Q — if the page blocks quitting, use Cmd+Option+Esc → Safari → Force Quit. Relaunch Safari holding Shift so the scam page doesn't reload.Cmd+Option+Esc → Chrome → Force Quit, relaunch, and don't restore pages.My iPhone shows a warning in Safari with a phone number. Real? No. iOS doesn't produce virus warnings in Safari, and Apple support numbers never appear in web pages. Force-quit Safari (swipe it away in the app switcher), then Settings → Safari → Clear History and Website Data so the page can't reload.
Can a Mac even get viruses from a web page? Merely viewing a page doesn't install anything on a modern Mac — infection needs a download that you open and approve. If you didn't install anything, a scan with the built-in protections (XProtect runs automatically) is all the reassurance available; if you did install something at the page's urging, remove it and treat it like the recovery checklist.
Tech support scam pop-ups · Fake Windows Defender warning · Fake Error #268D3 · Fake ZEUS virus pop-up · Fake blue screen scam · Fake renewal email scam · Clicked a phishing link? · Fake Apple security warning · "Your computer has been locked" scam · Social Security scam calls · Fake Amazon account alerts · Someone has remote access to my computer