Robert S. McNamara, secretary of defense from 1961 until 1968, said in an article published yesterday that nuclear weapons "serve no military purpose whatsoever" and should not be an element of NATO's defense.

McNamara said that he told Presidents Kennedy and Johnson that nuclear arms are "totally useless" and that both leaders agreed never to initiate their use, although "first use" was an official NATO doctrine during their administrations and remains so today. Kennedy never considered using nuclear weapons during the Berlin crisis in 1961, McNamara said, or the Cuban missile crisis in 1962.

"I know of nobody that knows how to limit a nuclear war once it starts," McNamara said. "And if it starts through error, there's a high probability you'll destroy the West through error."

McNamara co-authored an article last year recommending that the United States and its European allies renounce the first use of nuclear weapons in Europe. NATO currently keeps about 6,000 nuclear bombs, artillery shells, missiles and mines in Europe, and the alliance's strategy calls for using nuclear weapons if conventional arms fail to repel a Soviet attack.

This week, in an article published in Foreign Affairs and a news conference at the Arms Control Association, McNamara repeated his contention that such a strategy is suicidal, and he went further by saying the West should renounce "second use" as well.

In other words, he said, the United States should not launch nuclear weapons in response to a nuclear attack until the motives and extent of the enemy's action become clear.

Military strategists should not discount "the risk of bungling into a confrontation," McNamara said.

He called for a nuclear-free zone in central Europe. He said the presence of nuclear weapons near the front would force NATO to use them at the start of a conflict or lose them before they could be used.

"Most of them are junk, just plain junk," McNamara said of the 6,000 nuclear weapons. "They're old, they're unreliable, there's no way they can be used efficiently, and they can be removed entirely. The others should be moved back."

He said the same arguments should be applied to the nuclear Pershing II and cruise missiles the United States plans to deploy in western Europe beginning late this year. The plans have caused considerable controversy in Europe, and he said "there's no military requirement" for the Pershings.

But he said there is a "political requirement" for the missiles, because many Europeans believe the missiles are a sign that the United States would put itself at risk to defend western Europe. He dismissed that notion as an "unreality" and "misperception," but said the United States must contend with it.

"So I am quite content to see us deploy Pershings for the time necessary to change that perception," McNamara said.

He said there is some merit in the argument that the threat of nuclear war may deter the Soviets from launching an attack in Europe. But he said that deterrent threat is becoming "less and less credible," because the Soviets increasingly will come to understand that no rational western leader would use such weapons.

In addition, McNamara said beefing up conventional forces could offer an equally strong deterrent.