President Carter yesterday "deplored and "condemned" the sentence imposed on Soviet dissident Anatoly Scharansku, and told a crowd of thousands of West Germans that the United States will not retreat from the challenges of "a time when the enemies of democracy seem determined to test us."

Speaking from the steps of the German capital's Rathaus (city hall), the President expressed what he called "the sadness the whole world feels" because of the Scharansky sentencing.

"We are all sobered by this reminder that, so late in the 20th century, a person can be sent to jail simply for asserting his basic human rights," the president said.

Earlier, at a joint news conference with West German Chancellor Helmut Schmidt, the president used stronger language, saying he "condemned" and "deplored" the Soviet action in the Scharansky case.

Carter made no mention yesterday of any steps he plans to take to protect the action further, and American officials here said it was extremely unlikely that he would announce any such actions until he returns to Washington from Europe late Monday night.

Nevertheless, U.S. officials seemed confident that the president will announce further response to the Scaransky case when he returns to Washington.

At times during the overcast, cool day, Carter seemed particularly grim, although he smiled broadly during the warm reception given him by more than 5,000 people in the city hall square. He also spent a half-hour meeting in his limousine with White House aides Jody Powell, Hamilton Jordan and Gerald Rafshoon outside the U.S. Embassy.

Powell said later the meeting had to do with Scharansky and other matters that he characterized as routine.

In his speech at the city hall, Carter declared that the Scharansky verdict was "saddest of all for the Soviet people . . . who yearn like all others for peace and liberty, who have seen their own government pledge two years ago to respect those human rights and desires, and who now have seen that pledge broken once again.

"The struggle for human liberties is long and difficult, but it will be won," Carter added. "There is no power on earth that can long delay its progress."

Carter security is your security reaffirmed the U.S. commitment to the defense of Europe at what is widely viewed here as a time of growing Soviet-American tension.

"Our security is your security and yours is ours," he said.

"That is why the United States is increasing its commitment to NATO and will help to defend your land as if it were our own.

The speech struck a major theme of the president's first full day here, even though Soviet-American relations tended to overshadow other aspects of the visit.

U.S. officials suggested that one reason the White House was holding off announcing any further actions in the Scharansky case was to avoid further detracting from the purpose of the trip, which was scheduled to reaffirm American ties to West Germany and to enable the president to attend an economic summit conference here Sunday and Monday with Schmidt and the leaders of France, Britain, Italy, Canada and Japan.

Even so, last night Carter - delivering a toast at a state dinner - returned to the subject of relations with the Soviet Union, offering an echo of his "cooperation or confrontation" speech delivered June 7 at the Naval Academy in Annapolis.

"If the Soviet Union chooses to join us in developing a more broad-based and reciprocal detente, the world will reap untold benefits," he said.

"But genuine detente also includes restraint in the use of military power and an end to the pursuit of unilateral advantages, as in Africa today," he said. "And of detente must include the honoring of solemn international agreements concerning human rights and a mutual effort to promote a climate in which these rights can flourish."

"But whatever the Soviets decide," Carter added, "the West will do whatever is necessary to preserve our security while we continue the search for a lasting peace."

The President's directness on sensitive issues also apparently had an effect on Schmidt. The chancellor joined in with a rare public endorsement of the president's condemnation of the Soviet action on Scharansky.

He added that West Germans were also concerned about the recent sentencings in East Germany of a young man who resisted being drafted from supposedly demilitarized East Berlin into the East German army, and of East German economist Rudolf Bahro, a sharp critic of the communist government.

The chancellor said the American public must also be made aware that the number of people suffering persecution in Eastern Europe goes "far beyond those who at the moment are assuming such a prominent role in the public consciousness.

Bonn has generally been far more cautious than the Carter White House on human rights issues because of its ethnic and trade ties to the East, and its effort to maintain good relations with the Soviets.

Later, U.S. officials acknowledged that in their private meetings, Schmidt had pointed out to Carter that 75,000 ethnic Germans had come back from Eastern Europe in the past 18 months - a measure of how sensitive the human rights issue is for West Germans, who also want to keep the door open for visits to East Germany.

The president also levelled a sharp reminder to East Germany yesterday that it is not part of the 1971 four-power agreement that covers Berlin, and has "no legal nor legitimate role to play as a commentator."

The president's remark, which won warm praise here came after the East German government protested plans for Carter to be accompanied to Berlin today by Schmidt.

Throughout the day, Schmidt and Carter seized on every public occasion to heap praise on each other, and to emphasize repeatedly what the president called "the firm foundation of mutual purpose . . . and commitment to strong ties that bind us together politically, economically and military."

In one compliment that could come back to haunt Carter, he said: "I have never met any other world leader who has been more assistance in my comprehension of economic matters than has Chancellor Schmidt.

Schmidt and Carter will join five other Western leaders in an economic summit meeting that opens here Sunday, in which battles between still divergent German and American points of view seem like to emerge.

The president, in a brief exchange with reporters after a 21/2 hour meeting with Schmidt, in fact acknowledged that those discussions had been fruitful "in identifying those areas where our own national interests might be at some small variance."

At another point, Carter also described the talks as an opportunity "to reassess" the ties between the two key NATO allies, an indirect acknowledgement that there have been more than the usual amount of squabbles between the two capitals since Carter took office and that some kind of Bonn-Washington detente was now being mutually sought.