To do someone else a great favor which they don't really deserve, doing oneself a disfavor in the process. Small countries often have to pull the chestnuts out of the fire for their more powerful neighbors.
PULL ONE'S CHESTNUTS OUT OF THE FIRE
Meaning of PULL ONE'S CHESTNUTS OUT OF THE FIRE in English
American idioms English vocabulary. Английский словарь американских идиом. 2012