A federal appeals court on Tuesday again slapped down hedge fund investors in Fannie Mae and Freddie Mac — all but denying one more opportunity for the wealthy investors to cash in on a long-held investment.

The court, in a 2-to-1 ruling, upheld a lower court decision that Uncle Sam did not overstep its authority by seizing Fannie and Freddie’s profits since 2012.

Although the ruling bars hedge funds’ suits on those grounds, it does allow for certain shareholders to pursue breach of contract litigation.

Shares of Fannie and Freddie cratered on the news: Fannie stock tumbled 34.7 percent on Tuesday, to $2.71, while Freddie was off 38.1 percent, to $2.47.

Matt McGill, a lawyer representing Perry Capital, one of the hedge funds invested in Fannie, called the decision a “disappointment.”

Perry Capital has been an investor in Fannie and Freddie since 2010, just two years after the two were placed in government conservatorship during the financial crisis — and is a lead plaintiff in the case.

Perry “recognized before many others that [Fannie and Freddie] would become immensely profitable,” McGill told The Post.

Then, in 2012, just as the two were returning to profitability, terms of the bailout were modified and all profits were redirected to the Treasury Department instead of shareholders — a move referred to as the “net worth sweep.”

The ruling is important as Fannie has returned to the Treasury Department $68 billion more than the taxpayer bailout.

Shareholders are trying to get their hands on that cash.

Bill Ackman’s Pershing Square, also a Fannie and Freddie shareholder, filed an amicus brief after Perry Capital appealed the original ruling in 2015.