The Reagan administration, ending a two-year deadlock over the Washington area's plans for expanding the Metro subway system, released nearly $400 million yesterday to complete two major sections of the long-delayed Green Line in the District and Prince George's County along with other rail extensions.

The $391.2 million federal grant, described as the largest for any mass transit project in the United States, is designed to provide subway service to the low-income Anacostia area by 1991 and to add suburban Metro stations in Montgomery County, Alexandria and northern Prince George's.

The agreement -- a complex compromise drawn up after protracted bargaining -- cleared the way for Metro to finish at least 15 more miles of subway construction with funds the Reagan administration had long refused to release. The administration gained tight new controls over Metro spending.

Secretary of Transportation Elizabeth Hanford Dole hailed the accord as "a blueprint for all future federal funding" for Metro. "We can finally guarantee that the long-delayed inner Green Line, from U Street to Anacostia, can be built without additional funding from Congress," she said.

"It breaks the logjam," said Metro General Manager Carmen E. Turner. The release of the funds, which the Reagan administration had withheld despite protests from members of Congress, will allow Metro to expand the 69.6-mile system to 84.7 miles by 1992 and, probably, to 89.5 miles by 1994, she added.

The grant's release appeared to mark a turning point in the Metro system's often strained relations with the Reagan administration. The administration has sought to rein in Metro's soaring costs, Metro officials have accused the administration of circumventing congressional actions and delaying subway work.

Yesterday's agreement resulted from a last-ditch round of negotiations over a contract designed to embody conflicting federal and local aims. It also reflected repeated prodding by key House Appropriations Committee members, including Steny H. Hoyer (D-Md.) and Frank R. Wolf (R-Va.).

In addition, Dole has made plain her desire to get the Green Line opened. Delays in building the Green Line, Metro's only unopened route, have caused concern among federal and local officials because the line is designed to serve low-income areas where residents depend heavily on public transportation.

The Green Line's construction has previously been held up by protracted court battles, several neighborhood controversies and shortages of funds.

With yesterday's grant, Metro officials have pledged to complete several segments of the Green, Red and Yellow lines. By late 1990, officials said, the Red Line will be extended to Montgomery's Wheaton station. A Yellow Line spur to a Van Dorn Street stop in Alexandria's West End is to open in early 1991.

The Green Line is scheduled to be constructed in several stages, with service to Anacostia planned to start in late 1991. Although the Green Line's Shaw and U Street stations will be ready a year earlier, officials said, these will be served temporarily by the Yellow Line until the Anacostia stop opens.

The first Green Line service in Prince George's is targeted for late 1992, with a branch linking Fort Totten in Northeast Washington with Prince George's Plaza. At this point, the Metro system will encompass 84.7 miles, officials said, and any further expansion will depend on congressional actions.

If Congress allots more funds for Metro, according to yesterday's agreement, the Green Line is to be extended to two additional Prince George's stops, those at College Park and Greenbelt, by 1994. Prince George's County Executive Parris Glendening termed the accord "a tremendous victory."

With these stations, the Metro system would reach 89.5 miles, still markedly short of the 103-mile network envisioned by local officials. The accord allocates no funds for the remaining 13.5 miles, estimated to cost $2 billion, and the administration is opposed to any further federal outlays.

In endorsing the new contract, county and city governments that subsidize the Metro system have assumed enormous financial risks, local and federal officials contend. Metro officials believe Congress is likely to provide sufficient funds eventually to offset the risks.

First, the grant released yesterday is expected to fall more than $200 million short of the cost of completing and opening 84.7 miles. If Congress refuses to supply more money, county and city governments will be required to close the gap by furnishing local revenues or adopting cost-cutting measures.

Second, if Metro incurs major overruns in construction costs, officials said, local governments may be required to finance the added costs without any federal aid.

Whether Congress will continue to earmark funds for Metro in the next few years is unclear. President Reagan recently asked Congress to cut off spending for Metro. However, in an initial test, a key House subcommittee balked at the president's request and recommended more than $200 million for Metro next year.

The recent impasse over Metro funds was an outgrowth of earlier congressional effort to bail out the subway system. Under a landmark measure enacted in 1980, Congress authorized $1.7 billion to complete the proposed rail system. Metro officials soon found, however, that the amount was insufficient.

In 1984, Ralph L. Stanley, the Reagan administration's mass transit chief, launched a campaign to put a lid on Metro spending. The cost of building the rail system, once estimated at $2.5 billion, has soared to more than $9 billion.

Stanley's strategy was to withhold funds appropriated by Congress for Metro construction until the authority had drawn up a plan specifying the routes it could complete under the $1.7 billion authorization. The $391.2 million released yesterday had been appropriated by Congress in the past two years.

By September 1984, Washington area officials had devised a plan for expanding the rail system to 89.5 miles. Stanley then called for a contract embodying the plan and protracted negotiations ensued.

Last December, as the contract talks appeared to near an end, the Reagan administration switched tactics. The Gramm-Rudman-Hollings federal deficit reduction measure had been enacted by Congress and the administration said it could no longer endorse further spending for Metro.

Stanley then demanded a scaled-back contract. The compromise accord announced yesterday marked the end of these negotiations.

Stanley cited the new contract as a milestone, saying it represented the first time the federal government had put a limit on Metro's construction costs. Federal officials also argued that the contract would bar Metro from starting work on any subway extension that it lacks the money to complete.

The agreement requires periodic reviews of Metro's finances. It imposes restrictions on cost overruns and penalties for any default on the agreement. Two major companies, Day & Zimmermann Inc. and Stone & Webster Engineering Corp., have been hired by the federal government under a $1 million contract to monitor Metro's projects.

Metro officials argued that the agreement also provides benefits for the transit system in addition to the release of the $391.2 million. For example, they said, it contains provisions designed to prevent federal officials from withholding funds appropriated by Congress for Metro in the future.