What you saw was what I'd call a "malicious pop-up" - there's no infection at all. It's a scam web page disguised to look like a system warning and is also designed to be hard to close/dismiss (there's nearly always a toll-free number to call).
These can nearly always dealt with by: Force-quit Safari, then hold down the Shift key while re-opening Safari.
You may also want/need to go to Safari > Preferences: Clear history and website data.
Under normal circumstances, Safari (and other Mac apps) are constantly auto-saving, so that after a crash it will usually come right back to the same place. Most of the time that's a nice feature, but these pop-ups take advantage of it (they'll come right back after a restart). When you hold the Shift key while opening a Mac app, you're instructing OS X to "forget saved state" - to open with a clean slate.