A man suffered a fatal heart attack while refueling a ferry, resulting in a spill that dumped nearly 2,000 gallons of fuel into Hyannis Harbor on Saturday morning, a Coast Guard official said.

The man, who was not immediately identified, was gassing up the Grey Lady, a high-speed ferry operated by Hy-Line Cruises between Cape Cod and Nantucket.

According to Chief Petty Officer David Gilbert, he had a heart attack and died, but the fuel kept flowing, dumping an estimated 1,900 gallons into the harbor.

The harbor was closed as cleanup efforts began. Because of the foggy conditions, a Coast Guard vessel was dispatched to stand guard at the mouth of the harbor and keep boats from entering.

It was not known whether the man worked for Hy-line or for an outside contractor. A woman who answered the phone at the ferry service had no comment and referred all questions to the Coast Guard.