idiom
beat the rap
Meaning
to escape punishment or avoid being convicted
Example
He managed to **beat the rap** thanks to a clever lawyer.