Princess Cruise Lines has agreed to plead guilty to seven felony charges and pay a $40 million penalty for polluting the ocean with waste and then trying to cover it up. Federal prosecutors said the payment represents the largest-ever criminal penalty involving deliberate pollution by a ship at sea.

California-based Princess is a subsidiary of Carnival Corp., which owns multiple cruise lines that collectively comprise the world’s biggest cruise company.

At the heart of the criminal case lies one ship in particular, the 3,192-passenger Caribbean Princess, which prosecutors said used a “magic pipe” to bypass the ship’s usual equipment and illegally discharge thousands of gallons of oily waste into the ocean. The practice came to the attention of authorities after an engineer on the ship reported the problem to British investigators in summer 2013. The ship was sailing off the coast of England at the time, and the whistleblowing engineer quit his job when the vessel reached Southampton, England.

Officials from the Justice Department said the ship’s chief engineer and senior first engineer tried to cover up the practice, removing the magic pipe and ordering subordinates to lie to authorities. Upon the ship’s arrival in New York the following month,  U.S. Coast Guard investigators conducted an examination of the Caribbean Princess, during which some crew members continued to mislead them about the illegal dumping practice.

Investigators eventually determined that the ship had been making illegal discharges since 2005, the year after the ship was put into service. They also discovered a handful of other illegal practices taking place on the Caribbean Princess and four other ships — the Star Princess, Grand Princess, Coral Princess and Golden Princess. The practices included allowing salt water in to prevent alarms from sounding when too much oil was being discharged, and discharging oily bilge water when storage tanks overflowed in the engine room, according to the Justice Department.

“The pollution in this case was the result of more than just bad actors on one ship,” Assistant Attorney General John C. Cruden said in a statement Thursday. “It reflects poorly on Princess’s culture and management. This is a company that knew better and should have done better. Hopefully the outcome of this case has the potential not just to chart a new course for this company, but for other companies as well.”

In a statement, Princess said it regretted its actions — even as it blamed rogue employees — and said it had taken steps to be a better environmental steward in the future.

“We are extremely disappointed about the inexcusable actions of our employees who violated our policies and environmental law when they bypassed our bilge water treatment system and discharged untreated bilge water into the ocean,” the company said in a statement.

The company said that when it became aware of the problem in August 2013, executives cooperated with the Justice Department and the Coast Guard while also launching their own internal investigation.

“As a result of our investigation we discovered practices, on some other ships, where we were operating out of policy and in violation on environmental law,” the statement said. “Although we had policies and procedures in place, it became apparent they were not fully effective. We are very sorry this happened and have taken additional steps to ensure we meet or exceed all environmental requirements.”

As part of the plea agreement, cruise ships from eight Carnival companies, including Carnival Cruise Line and Holland American Line, will operate for five years under a court-supervised “environmental compliance plan,” which will require independent audits and a court-appointed monitor. Of the $40 million penalty Princess agreed to pay, $10 million must go toward community service projects to benefit the maritime environment — $3 million of that will go to environmental work in South Florida, and another $1 million will go to marine projects in the United Kingdom.

Read more at Energy & Environment:

For more, you can sign up for our weekly newsletter here and follow us on Twitter here.