Former president Jimmy Carter said tonight he got Israeli Prime Minister Menachem Begin to withdraw troops from Lebanon in 1978 by threatening to initiate action to cut off U.S. arms sales to Israel and sponsor a resolution in the United Nations condemning the invasion.

"Subsequent to that, quite quickly Israel did indeed stop the advance, withdrew and we initiated" the U.N. peace-keeping force in Lebanon, Carter said in a press conference at King Hussein's palace here.

"So there can be legitimate public actions by the United States in our best interest to preserve peace and avoid bloodshed," he said.

Carter told the story in almost parable fashion, in a way clearly intended to buttress his assertion at the beginning of his current tour of the Middle East that President Reagan should use greater U.S. leverage on Israel to remove obstacles to the Middle East peace process.

Carter's rendition of the story, however, differed from the recollection of some other officials involved in the episode. According to a former senior Carter administration official, the Carter threat came after the withdrawal of Israeli forces from southern Lebanon and referred instead to Carter's discovery that Israel had left behind six U.S.-made tanks in the hands of client forces led by renegade Lebanese major Saad Haddad.

It was the first time Carter has discussed publicly the details of his dealings with Begin during the 1978 invasion of Lebanon, although there have long been rumors about the private diplomatic exchanges between the two leaders during that period.

Carter said he sent the strongly worded message to Begin through Richard Viets, then U.S. charge d'affaires in Israel. Viets is now U.S. ambassador to Jordan and was at the press conference today. The former president said the message was the "maximum and proper persuasion that I could use at that time."

Carter strongly suggested that Reagan ought to use similar warnings to induce Begin to withdraw forces from Lebanon now and to halt the spread of Jewish settlements on the Israeli-occupied West Bank.

"The settlements policy of Begin is a major obstacle to the peace process and I can certainly understand the concern of the Arab countries and the Palestinians about this policy," he said. But, he said, "I am not privy to President Reagan's plans or the extent to which he will exert American authority."

He added, "I can't predict what is or is not possible to stop the settlements."

Carter arrived here yesterday from Israel on a two-day visit, meeting separately with both King Hussein and his brother, Crown Prince Hassan, who showed Carter slides and maps of the growth of settlements on the West Bank. Carter disclosed none of the details of his talks with Hussein, refusing to say whether the king had indicated whether or when he might join peace negotiations.

Carter suggested that Hussein needs the support of moderate Arab states and Palestinians before he can enter talks and, the former president said, the settlements and the Israeli occupation in Lebanon are "aggravating circumstances" blocking that.