C. Stanley Blair, 52, a U.S. judge in Maryland who had been an aide to vice president Spiro Agnew and an unsuccessful candidate for governor in 1970, died Sunday night after an apparent heart attack.

After spending much of the day on farm work at his home in Darlington, in Harford County, Mr. Blair ate supper and began watching "60 Minutes" on television. He experienced chest pains and was taken to Fallston General Hospital in Fallston, Md., where he died.

A judge on the U.S. District Court since 1971, Mr. Blair was nominated to the bench by President Nixon the summer after he was overwhelmingly defeated by Marvin Mandel in a race for the Maryland statehouse.

In the courthouse in Baltimore, Mr. Blair was known as an outgoing, gregarious man, courteous and charming, who quickly established a friendly relationship with everyone from clerks to fellow judges.

Counsel on both sides of cases that came before him expressed their respect and admiration for what they viewed as his fairness and his eagerness to reach to the heart of the legal questions under dispute.

In the 1970 gubernatorial campaign, Mr. Blair sought to make then-Gov. Mandel the issue, portraying him as a man who played politics with principles, and who would compromise on significant matters in the interest of winning reelection.

Mr. Blair also identified himself consistently with Agnew, and with the Nixon administration.

In the end, his crushing defeat (557,000 to 292,000) was attributed less to issues or identifications than to finances. Mandel spent $1.1 million, more than $400,000 of it on a media blitz. Mr. Blair raised less than half Mandel's total, and was able to spend only $47,000 for radio, TV and newspaper ads.

Mr. Blair, who was born Dec. 20, 1927, in Kingsville in Baltimore County, received bachelor's and law degrees from the University of Maryland. cHe served in the Merchant Marine for three years before entering college and served as an Army captain after finishing law school.

He practiced law in Baltimore for a year and for 11 years in Bel Air, in Harford County. A former one-term member of the Maryland House of Delegates, he failed in a 1966 bid to move up to the State Senate, losing in a close race to William S. James (D-Harford).

When Agnew was elected Maryland's governor in 1966, he chose Blair as his secretary of state. After Agnew was nominated by the Republicans for the vice presidency in August 1968 Mr. Blair was in effect Maryland's acting governor while Agnew campaigned.

After the victory of the Nixon-Agnew ticket, Mr. Blair served as the vice president's chief of staff until early 1970. At that time, with the Maryland Republican organization hard-pressed to fine a candidate to challenge the popular Democratic incumbent, Mr. Blair relinquished his post to make the race.

It was in December 1972, that Mr. Blair, by then a U.S. judge, impaneled a special grand jury to investigate corruption in Baltimore County and elsewhere in Maryland.

In August of the next year, Mr. Blair disqualified himself from overseeing that grand jury after it was announced that one of those being investigated was Vice President Agnew.

In one well known case that came before him, Mr. Blair upheld in 1972 the authority of the Nixon administration Pay Board to regulate wages.

He ruled in what was the first court test of the authority of the board, established by President Nixon to regulate salaries and wages under Phase II of his economic stablization program.

Mr. Blair imposed maximum $2,500 fines on a union and a food chain for agreeing on a 22 percent pay increase without seeking an exemption from the board's general 5.5 annual maximum.

Mr. Blair's survivors include his wife, the former Opal Linkous Whiteford, whom he married in 1964, a step-daughter, Cynthia Tutalo, who lives in Rhode Island, and his father, Charles Edward Blair, of Hartford County.