bitter medicine
Literally medicine that tastes bitter; often used metaphorically for something unpleasant but beneficial, like tough advice or a harsh lesson.
This medicine is bitter, but it works well.
His advice was a bitter pill to swallow, but it helped later.
Compound of 苦い (bitter) and 薬 (medicine). The metaphorical use is a calque from English 'bitter pill' or similar expressions.