Could not exit trade due to margin shortfall

Last week I took a trade and made an Iron Condor. Took higher number of lots than the usual. Sell orders and Buy orders were executed perfectly. Checked the funds and saw only very little margin remaining but it was not negative.
After some time there was little M2M loss and I decided to exit the trade. So when I placed Exit (Buy) orders for sold legs, I got the message that there is insufficient margin. Margin required to buy is Rs. xxxx. I tried exiting the sold position multiple times but kept failing. Helplessly than I tried to sell bought legs where again there was margin error. Also I was afraid that if bought legs are sold than margin required would exceed even higher because I will be unhedged now.

Trade kept going against me. In the panic I quickly had to transfer some funds from bank A/c to Zerodha and than only I could come out of the trade.

Not sure what I did wrong. If there was margin shorfall the trade shouldn’t have been executed at the first place. Had I not had additional funds in bank I would not have been able to quit the trade.

Plz advice what went wrong here.

@Siva