I’m no expert, but am I understanding correctly that you logged into wp_admin, went to the Settings page and changed the WordPress Address and/or Site Address?
If so, when I ran myself into that in the past, I fixed it by doing a find and replace in my database using phpMyAdmin. I searched for the new URL (example2.com) and replaced it with the previous URL (example1.com), essentially resetting it to its previous state. If you have one, you could also restore a backup of your DB and that should fix it (a good incentive for always making a backup before you change settings or update plugins). If all you did was add or remove “www,” you should be able to search for “//www.example.com” and replace it with “//example.com” (or vice versa; I included the forward slashes so you don’t end up with www.www.example.com or something like that). Of course, before you make any changes, export a backup of the DB in case things get worse so you can just restore!
When I had this (or a similar) issue, I made the change in preparation to migrate the site to a different domain, then the client wanted to make some changes so I had to undo that change.
Where you actually need to make that change is probably somewhere in the server configuration or maybe even the DNS settings with your registrar (look for “forwarding” and/or CNAME records—something along those lines). If you’ve recently activated SSL, there may be something wrong in the way your certificate was set up.
In other words, I don’t think you had a WordPress problem until you changed one or both of those URLs. Making those changes created a WordPress problem that hopefully my answer will help you fix, but I think your initial issue is more likely to be with your server or DNS settings.
Again, no expert, but hopefully that gives you somewhere to start!