The Reagan administration was ordered yesterday to release nearly $180 million in revenue-sharing funds that had been sequestered under the Gramm-Rudman-Hollings budget law.

The District will receive $676,000 of the funds.

U.S. District Judge Joyce Hens Green ruled that the money was illegally transferred from the revenue-sharing trust fund to the general treasury and should be paid to eligible cities.

Treasury Secretary James A. Baker III was given until Aug. 18 to distribute the money. The largest grant is $10 million for New York City.

Alan Beals, executive director of the National League of Cities, called the decision "a clear and direct statement affirming our belief that the funds were illegally withheld, and we hope that the Treasury Department will abide by this decision."

The Justice Department, which represented Baker in the lawsuit, had no immediate comment.

Green's ruling came in a lawsuit filed by the league, the U.S. Conference of Mayors, the National Association of Counties and 10 city and county governments. The plaintiffs were represented by the Public Citizen Litigation Group.

The dispute involved President Reagan's Feb. 1, 1986, sequester order under the Gramm-Rudman-Hollings budget law that set aside 4.3 percent of budget items, including $180 million from the revenue-sharing trust fund.

Green ruled that the Revenue Sharing Act and the Gramm-Rudman-Hollings law did not give the administration authority to transfer the money from the fund.

"The purpose of sequestration, as opposed to cancellation (which Congress expressly mandated for other programs) was to reduce the size of the 1986 deficit, not the deficit in succeeding fiscal years," she said.

"The payment of the remainder of the 1986 grants in fiscal year 1987 is not inconsistent with the Gramm-Rudman scheme," she ruled.

The judge also found that even though Congress voted to terminate revenue sharing after fiscal 1986, it provided that money left in the program's trust fund would be paid to the cities.

In 1986, Congress appropriated $4.3 billion for revenue sharing.

J. Thomas Cochran, executive director of the U.S. Conference of Mayors, estimated that Chicago will receive $2.6 million, Los Angeles $2.2 million and Detroit $1.3 million.