Safari is part of macOS, and updated with macOS.
If you’ve replaced Safari with some apparently-wrong version, restore Safari from your Time Machine backup.
If you have no backup, go fix that now and get backups going, and then you can install the macOS 10.13 combo update.
For a case such as this, a newer version of Safari usually means upgrading macOS. What upgrades are available depends on which iMac model this is; both model and model year. With both the model and model year, we can look up your upgrade options.