One of the country’s largest servicers of federal student loans has badly mismanaged debt forgiveness programs for public service workers, significantly raising repayment costs for hundreds of thousands of borrowers, according to a lawsuit filed on Wednesday by the attorney general of Massachusetts.

The loan servicer, the Pennsylvania Higher Education Assistance Agency, which operates under the name FedLoan, has made copious errors, potentially miring many students in debt far longer than they expected, according to Maura Healey, the Massachusetts attorney general.

“This company’s actions have jeopardized the financial futures of teachers and public servants across the country,” Ms. Healey said.

The company, based in Harrisburg, Pa., holds an exclusive contract with the Education Department to service all loans enrolled in the public service loan forgiveness program and the Teacher Education Assistance for College and Higher Education Grant program, or TEACH, which offers assistance to those who teach in high-need areas.