BOSTON — The state Appeals Court has told a New Hampshire railway company and three of its subsidiares to pay up.

The court rejected a request by Pan Am Railways, Inc. to hold off on paying criminal fines totalling $500,000 for failing to report a hazardous-materials spill and contamination in its rail-yard property in Ayer four years ago.

On the evening of Aug. 8, 2006, a locomotive left idling at Pan Am Railways’ rail yard in Ayer spilled 900 gallons of diesel fuel onto the ground.

Each of the companies involved failed to immediately notify the state about a fuel release, of which numerous employees were aware.

The state Department of Environmental Protection was notified of the spill by an anonymous phone call.

When the companies learned that DEP had been notified, they directed employees to move the leaking locomotive to the Willows, an area in the vicinity of the town of Ayer’s public drinking wells.

In April 2009, Middlesex Superior Court Judge Elizabeth Fahey ordered Pan Am Railways , Inc., of Nashua, a privately owned freight railroad that serves northern New England, from Mattawamkeag, Maine, to Rotterdam Junction, N.Y., to pay a $125,000 fine to the state.

Fahey also ordered the Maine Central Railroad Company, which owns the locomotive from which the spill occurred; the Boston & Maine Corp., which owns the Ayer rail yard; and the Springfield Terminal Railway Co., which is the operator of both the locomotive and the rail yard, to also each pay a $125,000 fine to the state.

And in an unusual move, Fahey ordered that the defendants are prevented from receiving bonuses of more than $100,000 in a 12-month period, excluding salaries, until they have paid the fines.

On April 15, 2009, the companies deposited $500,000 into a joint interest-bearing account in the names of each of the corporations and the attorney general, to be released after all appeals are exhausted.

The companies appealed to a single justice of the Appeals Court, seeking a “stay of execution,” saying depositing the $500,000 in a joint account is the equivalent of paying the fine. That appeal was denied. The companies appealed again to the full Appeals Court.

Justice Kent B. Smith, in writing the decision, explained that in deciding to stay a sentence, the judge should consider if the issue has a reasonable possibility of success on appeal.

The companies argued they were entitled to a stay because they don’t pose a security risk and some of the issues in this case are novel.

Smith wrote that the trial judge, in her denial of the initial request for a stay, concluded the companies posed a “tremendous danger” to the community and the public given the magnitude of the spill, the lack of procedures in place, and the attempts to cover up the spill.

While there were some novel legal issues in this case, Fahey noted that the companies failed to show even a reasonable possibility of success upon appeal.