Poland's Supreme Court has acquitted a man who had served 18 years in prison for rape and murder of a teenager that the judges now say he couldn't have committed, in a case that has shocked the nation.

Poland's right-wing government has highlighted the case of Tomasz Komenda as an example of, what it says, is a malfunctioning justice system that needs deep reform.

Komenda, in his early 40s, left prison in March after prosecutors revisited his case and came to the conclusion that he couldn't have committed the crime. They appealed to the Supreme Court for his acquittal.

The court on Wednesday acquitted Komenda, who can now seek damages.