Exactly. HR is the company's first line of defense. For example, they do things like presenting educational seminars on such topics as sexual harassment or illegal discrimination, to try to prevent employee behavior from getting to the point where lawyers would actually have to get involved. Or they get rid of employees who might cause liability to the company through their actions.
This sometimes has the side-effect of protecting employees and making sure that employees get everything they're entitled to under federal/state employment laws, but their main goal is to protect the company from civil and criminal liability.