New York City agreed to pay the U.S. government $4.3 million to settle a civil fraud lawsuit accusing the city's fire department of accepting tens of thousands of improper Medicare reimbursements for emergency ambulance services.

The accord signed on Tuesday resolves claims that the city cheated the U.S. Department of Health and Human Services out of millions of dollars from October 2008 to October 2012 by submitting claims for services that were not medically necessary, violating the federal False Claims Act.

According to court papers, part of the problem may have been linked to the New York City Fire Department's ("FDNY") ambulance billing contractor.

RELATED: Massive church fire may have been caused by candles: FDNY

The U.S. Department of Justice said that in a review sought by the FDNY, the contractor in June 2010 found just one Medicare reimbursement denial for unnecessary services over a period of several months, though the number of improper reimbursements was at the time averaging more than 1,000 a month.

The FDNY alerted the office of U.S. Attorney Preet Bharara in Manhattan to the improper reimbursements in December 2012, and adopted new claims procedures nine months later.

“As a result of this joint look into Medicare billing practices at the FDNY, the agency has completely revamped its policies and has stronger procedures in place to reduce the risk of recurrence and to immediately correct erroneous or improper payments," the city's law department said in a statement.

Bharara's office had no immediate comment.