Kevin Lamarque/Reuters
A federal appeals court made the decision on Tuesday, according to Bloomberg.
Shareholders had argued that the government illegally seized profits from the companies, following the 2012 decision to start collecting a share of earnings every quarter.
Some contract-based claims related to liquidation preferences and dividend rights were returned to the district court for further proceedings, Bloomberg reported.
On Friday, Fannie Mae said it would pay $5.5 billion in dividends to the US Treasury. With that payment, to be made in March, the company would have paid a total of $160 billion in dividends to the government.
The Federal Housing Finance Agency placed both companies under its guardianship - known as conservatorship - in 2008, and they received a $187.5 billion bailout in the wake of the housing crisis.
Gary Cohn, director of the White House National Economic Council, told The Wall Street Journal that the administration plans to direct the Treasury to review the role of Fannie and Freddie. Treasury Secretary Steven Mnuchin said in January that "we've got to get them out of government control."
Fannie Mae's and Fannie Mae's over-the-counter shares plunged more than 30% after news of the court decision crossed.