Tough luck. It happens to everyone. It happens to the AIs, it happens to human players. There are a few CBs that do not allow change in war leader. Claim Throne, Revolution, Cleansing of Heresy, Revoke the Electorate. Other than that, there is only one thing you can do: be careful and get allies of your own. You had no allies for yourself?
In one of my games as Swahili, Russia declared Holy War on just three provinces Kazan no less than 4 times. Russia could never annex Kazan. Why? Kazan was allied to Yemen. Yemen took leadership, and calls its ally, Mamluks. Mamluks are much stronger than Yemen, so they take the leadership. Mamluks call Spain, and Spain takes the leadership, and brings Spain's allies Netherlands and Denmark. Russia could never get Kazan and it was so sad, so stupid and so amusing all at the same time.
Likewise, I was playing as Ulm > Germany and I got called to defend the Ottomans when a coalition of Persia, Crimea and Nogai declared punitive war on them. I took over the control, and I called Russia, France and England in. The anti-Ottoman coalition was crushed.
It can happen to players as well. I was declared war twice in a row when I barely had 5 provinces, one of them still a colony, as Sukhothai. I had stronger allies, and Zhou assumed the leadership. Just as you cannot peace out the target of the war separately as an attacker, as defender the control went to Zhou and I couldn't peace out anyone on my behalf. Zhou paid off one war (with their money), and surrendered two of my provinces to Aceh. It's just the way this game plays... sometimes you laugh as you get it to your advantage, sometimes you cry when it works in the enemy's favor.
Imagine this. Let's say you were also allied to Austria. If you declare on Pomerania, Austria won't join since the AIs almost always join on the defensive side. But for Hamburg, Austria might join on the offense, and if they do, they can't join on both sides at the same time. Similarly, if you allied Austria, declared war on someone else - let's say, Saxony - and brought Austria in. Now one month later you also declare war on Hamburg - now you have two wars going on. The same cascading alliance will happen, but this time Austria cannot answer Pomerania's call to arms because they're already fighting a war on your side.
Managing the alliances is tricky. I personally think diplomacy is way more important than your military strength for this very reason. As Ulm, I had barely 30k units while Austria had more than double that number. I could still declare war against Austria and win, because I brought Bohemia, France and the Ottoman Empire on my side.
Fighting a war doesn't always mean you're enemy to that nation forever. Well, you might be their perpetual enemy if you took too much aggressive expansion penalty, but usually not. I actually declared war on Bohemia's ally, with the intention to bring Bohemia into the war, to revoke a reform. We allied again as if nothing happened.