Virginia declared victory over Maryland last night in a pork-barrel battle for the prestigious National Science Foundation, as Sen. John W. Warner (R-Va.) announced that the agency is headed for a new home in Arlington.

After months of behind-the-scenes wrangling between lawmakers from Maryland and Virginia, Warner released a letter from federal officials ordering the foundation to move from the District to Arlington's Ballston area. The NSF will move to the Stafford Place project, developed by Paul V. Cali, on Wilson Boulevard near Interstate 66 and the Ballston Metro station. The agency will occupy 400,000 square feet in a building to be constructed later. Cali declined to comment last night.

The foundation, which finances and coordinates advanced scientific research, is expected to bring increased visibility and economic benefit to its new location. The facility would house about 1,400 employees and play host to 3,500 visiting scientists each year. The long-term lease has an estimated annual cost of about $12 million.

For several months, Warner and Sen. Charles S. Robb (D-Va.) have waged a quiet war with Sen. Barbara A. Mikulski (D-Md.), who used her position on the Senate Appropriations Committee in an effort to bring the foundation to Maryland.

In September, after federal officials tentatively had identified Arlington as the agency's new home, Mikulski tried to derail the move by forbidding the foundation to leave its current headquarters.

"I think this letter is a real step forward in achieving a new home for the foundation in Virginia," Warner said.

A spokeswoman for Mikulski, Linda Marson, said last night she had not seen the letter and could not comment. Mikulski has questioned whether the search for a new headquarters was fair to sites in Maryland.

The letter, dated Nov. 30, is from James C. Handley, the General Services Administration's regional administrator, to Frederick M. Bernthal, the foundation's acting director. It says that failing to move to the Ballston site would be "counterproductive to our mutual goal of ensuring that NSF is economically housed."

Although the foundation can appeal the directive, aides to Warner said the move had been approved by senior officials in the Office of Management and Budget and the White House, making a reversal unlikely.

The controversy has put NSF in a difficult political situation. Mikulski heads the Senate Appropriations subcommittee that reviews the foundation's budget, and agency officials have been reluctant to offend her. Officials have also said they are concerned that the cost of moving, about $16 million over two years, could hit them hard in times of tight budgets.