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.