Top executives at Brooklyn energy company KeySpan sold millions of dollars worth of stock and stock options before announcing a significant loss that sent the company’s shares tumbling.

KeySpan’s Roy Kay unit – which provides plumbing, mechanical and electrical contracting – was in financial straits for three months before the company held a heads-up conference call with Wall Street analysts in mid-July.

The problems at the unit eventually led to a $30 million after-tax loss at KeySpan that sent the stock tumbling.

In the meantime, as many as 11 executives made $5.8 million by selling stock and options.

“One may question why these executives were selling at a time before the write-off was made known,” said Lawrence Sucharow, a securities attorney with Goodkind Labaton Rudoff & Sucharow.

No complaints have been filed at either the Securities and Exchange Commission or the New York Stock Exchange.

SEC lawyer Robert Anthony said: “If a director or officer sells based on information they have, they could be charged with insider trading.”

None of the executives who traded before the stock drop would comment. Company spokesmen said the executives were entitled to trade during that period, and there was nothing wrong with what they did.

General Counsel Stephen L. Zelkowitz made $661,078 selling stock and options, while William K. Feraudo – an executive vice president and president of the Roy Kay unit – pocketed $929,915, according to SEC filings.

Robert J. Fani, president of KeySpan Energy Services & Supply, walked away with $1,012,905, and KeySpan CFO Gerald Luterman made $311,200.

KeySpan stock hit its 52-week high of $40.82 on April 17 and its executives were permitted under company rules to trade starting in mid-May.

The stock hit its 52-week low of $29.35 on July 24 – after the earnings report was officially released – and closed yesterday at $31.

Most of the trades made by the execs were between $38 and $40 a share.

On April 20, KeySpan fired the heads of the Roy Kay unit because of suspected financial improprieties.

“We clearly knew there was a problem in April, and we tried to solve it,” said Bob Mahoney, a KeySpan spokesman.

But he added that the company didn’t know the Roy Kay problem would affect the larger company’s finances – or be “material,” in Wall Street parlance – until later.

“There are degrees of knowing,” Mahoney said. “In early June we suspected there was a problem, but we did not know it was material.”

KeySpan on June 1 closed its window for executives to trade company shares – a week ahead of schedule – because of the expected losses, officials said. And they warned Wall Street about the problems on July 17.

On July 16, however, a stock that typically traded well under 500,000 shares a day saw volume jump to 3.4 million shares. And the stock, which had been still hovering at $38, started to fall, closing at $34.50.

On July 17, the day analysts were notified of impending losses, 1.9 million shares were traded, and it closed at $32.