After more than two years of negotiation, the Maryland state government has agreed to locate a new multimillion-dollar district court facility and a state services center adjacent to the Prince George's County Courthouse in Upper Marlboro.

Both County Executive Lawrence G. Hogan and the man he succeeded in the office, Winfield M. Kelly Jr., supported the site just south of the courthouse that was chosen over a more remote six-acre site that had been earmarked for a national tobacco museum.

The Maryland Executive Management Board, made up of the heads of three state cabinet departments involved in public construction, voted recently to accept the location after the county agreed to shift the route of a proposed Upper Marlboro ring road to give direct service to the new facility.

The county also sold $2 million in bonds to renovate Sasscer Junior High School as a school administration headquarters, permitting the present headquarters on the court building site to be demolished.

Larry Klemovitz, executive secretary to the Executive Management Board, who confirmed the county's announcement of the agreement yesterday, estimated the cost of the new building at around $7 million, depending upon its size. In addition to the courts, he said it may include offices dealing with vocational rehabilitation, juvenile services, parole and probation, public defender services, property assessments and taxation, state income and gasoline taxes and civil defense.