to be worth it, to be worthwhile
A viagem foi cansativa, mas valeu muito a pena quando vi aquela praia.
The trip was exhausting, but it was so worth it when I saw that beach.
The key to valer a pena is the word pena, which here does not mean "feather" but "suffering," "trouble," or "hardship" — from the Latin poena (penalty, pain). So the expression literally says something is "worth the trouble": the reward justifies the effort and suffering it cost.
Source: Ciberdúvidas da Língua Portuguesa.
Falando's Idiom Trainer teaches you to recognize idiom meanings and create sentences using them, so you can speak like a Brazilian.