The Gemara in Pesachim (ה:) says if you are holding Chometz for a gentile and Pesach comes you have to burn it. How is it possible to say that: it is Gezel Akum and even if you pay him back you are still stealing the actual item?
True, but at this point the item deposited with you is going to cause you harm (because you'll be violating the mitzvos of בל יראה ובל ימצא). So, logically, you should be allowed to get rid of it.
A possibly analogous case is in Shulchan Aruch, Choshen Mishpat 292:8, where a person who is holding money or valuables for someone else is threatened by thieves, and he gives them the deposit in order to save himself. The rule there is that if he's not particularly wealthy (אינו אמוד), then we assume that the thieves were attracted by the rumor that he's got something valuable in his house, and then he is indeed exempt from having to repay the owner - because the deposit itself is what caused all the trouble in the first place. (Here, in the case of the chametz, he is indeed liable to the gentile to replace it - otherwise it would be של אחרים and he wouldn't have to get rid of it anyway - but that's because the Jew accepted this responsibility along with the chametz, and it is also the law of the land that he is so responsible - see Shulchan Aruch Harav 440:9.)