Geoffrey Arthur Prime, a long-time Russian-language specialist for British intelligence, pleaded guilty today to passing secrets to the Soviets that did "exceptionally grave damage" to Britain and its allies over 15 years.

Sentencing Prime to a total of 38 years in prison, Britain's chief justice, Lord Lane, called him a "ruthless, rationally motivated spy." In his work for Britain's main electronic intelligence agency, Prime gained access to matters of "the very highest secrecy," the prosecution said, and provided the Soviets with vast quantities of information.

While details of what Prime gave the Soviets were not disclosed in open court, the description of his activities today appeared to confirm estimates by American officials that the Prime case represents one of the most serious Soviet penetrations of Western intelligence since World War II. For nine years ending in 1977, Prime was deeply involved in signals intelligence -- the interception of Soviet communications by Britain and the United States.

Prime, a gaunt, disheveled 44-year-old man, listened grimly as Attorney General Sir Michael Havers presented the evidence against him and flinched as the sentence was read. He wept softly when his wife, Rhona, who first told police of his espionage, testified that he is now "totally repentant and remorseful."

A 30-page confession given by Prime to police, along with what the state called "the indispensable tools of a modern spy" found in his home, formed the basis of the prosecution. The statement discloses that Prime first contacted the Soviets while stationed with the Royal Air Force in West Berlin in 1968 because he felt "sympathy" for the Soviet regime.

Following that approach, he was twice given security clearance by British intelligence, although he traveled to East Berlin for Soviet spy training and met repeatedly with Soviet agents in Vienna while rising through the ranks of the government's Joint Technical Language Service. The statement said his last contact with the Soviets was in Potsdam, East Germany, in 1981.

Prime's espionage was finally uncovered only after he confessed to his wife last April when police questioned him in connection with sexual attacks on three young girls. He had been identified in a routine check of cars seen in the area. Prime also pleaded guilty to those offenses today. The court was shown a box of 2,287 index cards Prime kept on the contacts he made, mainly by telephone, with potential sex victims.

The failure to detect Prime's spying, despite his behavior and movements over so long a period, has aroused expressions of angry dismay from British politicians about security procedures in intelligence agencies. Prime Minister Margaret Thatcher will make a full statement on the case to Parliament on Thursday, expected to focus on the security question.

The prosecution today specifically denied American press reports that Prime had identified the location of nuclear warheads or endangered the lives of Western agents. The Washington Post, quoting intelligence sources, reported on Oct. 25 that he had done so. In its Thursday editions, The Guardian reports that officials at Cheltenham "need to know the day-by-day location of all NATO forces" and the identity of intelligence agents in the Soviet Bloc in order to issue instructions in times of crisis. The newspaper does not say Prime gave that information to the Soviets.

Today's session in Courtroom One at London's Old Bailey lasted just under two hours. About 20 minutes was closed to press and public as Havers gave Justice Lane an account of what secret material Prime told police he had turned over to the Soviets. The balance of the hearing consisted of Prime's guilty pleas, a lengthy statement of facts by Havers, testimony by Prime's wife and remarks by the state-appointed defense attorney, George Carman, one of Britain's most famous lawyers.

Prime, his deeply lined face ashen, pleaded guilty in a soft voice to 10 counts in two indictments covering the sexual offenses and espionage. The spying charges were drafted to include a period between the end of l967 and last April, although his "persistent communication with the Russians" actually covered a slightly shorter time span, according to the prosecution statement.

The statement said Prime joined the RAF in 1956, served in Africa and was transferred to Berlin in 1964 after completing a Russian course. He approached the Soviets in 1968 by handing a note to a Soviet officer at a West Berlin checkpoint. A metallic cylinder was attached to his car with directions to a railway station where he was met by Russian agents -- identified to him as Igor and Valya -- and he began to deliver them classified material.

He returned to Britain that summer, was hired by British intelligence and told to report for duty at the end of September. Prime returned to East Berlin where, according to the statement, he "received extensive training in the arts of a spy," including the writing of invisible messages, radio transmission and deciphering of coded instructions. He was also given several hundred pounds, the first of a number of relatively small payments over the years. The largest sum was about $6,800.

Prime was assigned the code name "Rowlands" and a password for meeting contacts. In response to the agent saying, "I believe we met in Pittsburgh in 1968," Prime was to reply, "No, at that time I was in Berlin."

From then on, Prime was in regular communication with the Soviets and received supplies at various drop points in the English countryside. But there was no record of his having personal contact with Soviet agents in Britain. Until 1976, Prime worked in London for the Joint Technical Language Service, which is a unit of the Government Communications Headquarters, the main electronic espionage agency, known by the name of its base at Cheltenham, 80 miles from London.

He transferred to Cheltenham itself in 1976 and worked there until he resigned about 18 months later, telling his wife he was tired of the pressure in intelligence work. It was apparently after a promotion in 1975 that he began to gain access to the most sensitive information. Prime went to Vienna on several occasions to meet with his Soviet "controller" and was told, the statement said, that should he ever defect he would be given a pension and the rank of colonel.

In the fall of 1977, after quitting his job, Prime twice booked flights to Helsinki intending to defect but said he decided not to go because of his wife and her three young sons.

The Soviets next contacted him in April 1980 and directed him to a cruise ship on the Danube where he turned over 15 rolls of film of top-secret documents and other material taken while he worked for the government, the statement said.

The final contact came in October 1981 when, at Soviet request, Prime went to Potsdam and was "closely questioned about allied activities which were top secret." Prime said he has not heard from the Soviets since.

In their investigation of his home, police found a wide array of espionage equipment which was displayed in court. Included were a battered briefcase with a false bottom, a short-wave radio, pads for sending coded messages and innocent-looking letters intended as cover for invisible messages.

When confronted by police with the espionage allegation, which he only learned later came from his wife, Prime denied the charge. After repeated questioning, he changed his mind and gave a confession which went on for two days. In its final words, Prime told police he began spying as a "result of a misplaced idealistic view of Soviet socialism . . . compounded by psychological problems within myself. . . . I am . . . deeply ashamed."

The sentence by Justice Lane took account of the prosecution assertion that Prime gave the Soviets material that would cause "exceptionally grave damage to the interests and security of this country and its allies." Prime must serve at least one-third of the term of 38 years.