To risk oneself for someone else’s benefit; to take a dangerous or thankless task (literally: to pull chestnuts out of the fire).
上司のミスを隠したせいで、彼が火中の栗を拾う羽目になった。
Because he covered up his boss's mistake, he ended up taking the blame.
友人の頼みで火中の栗を拾うことになったが、報われなかった。
I took a risk at a friend's request, but it wasn't rewarded.
その役割は目立たない上に危険なので、誰も火中の栗を拾わなかった。
No one took on that role because it was dangerous and unrewarding.