In my native language when someone is well-intended to help someone else and does something but he ends up taking the blame or getting hurt, we say, "he wanted to be blessed by God, but got burnt by flames". I did some search and I just found this:
Many go out for wool and come home shorn.
Which means many seek to better themselves or make themselves rich, but end by losing what they already have.
I feel this proverb doesn't serve my purpose since it's more about a person who's looking for his own benefits rather than others'.
Let me give you two different contexts that we normally use the proverb/idiom and I'm looking for its English equivalent:
A: John got fired yesterday, then Paul went to talk to the boss to keep John on board but he got fired, too.
B: Poor man, [he wanted to be blessed by God, but got burnt by flames].
Or two men get in a fight punching each other. Another meddle in to break up the fight while he get a punch, too. Here also we say,
[he wanted to be blessed by God, but got burnt by flames].
Note it can also be used when you lose your money/properties, too. For example a company tries to keep another company in business by helping them or loaning them some money. The latter company sinks anyway, the former company makes a tremendous loss consequently.