At the coup, she was praisingly compared to Esther, Deborah, and Judith, and the king wrote a letter thanking her for having "saved" him.
She was praisingly compared to Esther, Deborah, and Judith. This was at the coup. The king wrote a letter. This was at the coup. This letter was thanking her for. This letter was having "saved" him.