Just a side note: There would've always been a heir, a next guy or girl in line. Many families needed a couple of generations (take the Carolingian dynasty) to seize power. This would've been incredibly difficult.
I think to properly answer this question, one needs to study a lot of medieval history and law. If this is supposed to be a serious book you want to sell, I would advice you do that. I didn't do that beforehand, I hope you do not mind. Here are some ideas, I believe combinations of those would be better than each one individually:
Straight up lie. Tell them you are a legal heir. Forge some documents. If you do some bribes, they might believe you.
Get religious support. You can most likely buy a local bishop (or whatever they have in your world). That doesn't mean he has to be corrupt, maybe just make a large donation to some monastery. He might not have the possibility to say no. If you have the church behind you, you have god-given authority.
Get the city elite to vote for you. You should maybe transform your city state into something other than a monarchy in the process (what exactly is up to you), but many leaders in the middle ages got their authority from votes, even monarchs. Your state is only as stable and youYou, the ruler, are only as powerful as other people with influence allow you to be. A medieval ruler was nothing without nobility or at least the patriciate behind them. You have to secure alliances either way, so you might as well secure your control via vote. How do you do that? That's a topic for another question and has various answers.
Talk to another (local) power. So everyone in that city state that didn't marry much with anyone and was rather independent is dead? Did anyone ever truly like them? Well, what a great opportunity for local powers to get a ruler on that throne that will change all of that. One might be able to (slowly) take control of the city and solve some problems. There were always problems and disputes between states. If you have a local power backing you up, others might stay quiet because they are scared. Maybe you can even get the support of a bigger empire nearby. Alliances of cities were a nasty business for bigger empires (that had enough on their hands staying a single entity), they would very much welcome to break that alliance the easy way and if they get some bribes and promises from you in the process - all the better. You do not have to weaken your state with this option if the foreign power behind you wants to keep an equilibrium between the various states in the region. They might even support a strong and independent "fantasy Pisa". Very often a strong ally is a good ally.