Harrison Arlington (Pete) Williams Jr., facing certain expulsion, resigned yesterday after 23 years in the Senate, declaring that "time, history and almighty God will vindicate me."

In an emotional final appearance in the Senate chamber, the 62-year-old Williams, convicted of bribery and conspiracy in the government's Abscam "sting" investigation, said he was leaving with "good spirits, a good heart and a strong resolve."

"I have fought a good fight, I have finished my course," the New Jersey Democrat said softly, quoting from St. Paul. "I have kept the faith."

The Senate chamber was quiet as Williams spoke, his 99 colleagues frozen in their seats. The galleries were packed.

It was one of those rare, historic moments that the Senate handles with such pomp and dignity.

Only four other senators have resigned under a cloud. And in abandoning his battle to keep his seat, Williams avoided the likelihood of becoming the first senator to be expelled since the Civil War and the first ever on charges of bribery.

He did so without acknowledging wrongdoing. "I did not wish to see the Senate bring dishonor to itself by expelling me," he said.

He signed one of two copies of his formal resignation letter as he sat in his seat in the second row of the Senate. Addressed to Vice President Bush, who is president of the Senate, the letter said:

"I herewith tender my resignation as a member of the United States Senate from New Jersey, to become effective at the close of business on Thursday, March 11, 1982."

After the Senate recessed, Bush went to the second-floor gallery and embraced Williams' wife, Jeanette, who had watched the entire expulsion debate.

Williams, the third senator in history to be convicted of a felony, told the Senate, which had devoted six days to the expulsion debate, that he decided to resign only after becoming convinced that the Senate would undertake a thorough investigation of alleged government misconduct in the Abscam investigation.

A resolution calling for such an investigation was introduced a few hours later by Sens. Alan Cranston (D-Calif.) and Ted Stevens (R-Alaska) and referred to the Senate Rules Committee.

Later, Williams and his wife were cheered as they entered the rotunda of the Russell Senate Office Building. He told a news conference that he was "not a broken man," and said he hoped that New Jersey voters "are not disappointed that I resigned."

Williams, a liberal stalwart and chairman of the Labor and Human Resources Committee when the Democrats were in the majority, was the only senator among seven members of Congress convicted in the Abscam undercover investigation. He was also the last to leave Congress. Rep. Michael Myers (D-Pa.) was expelled from office; the other five either resigned or were defeated at the polls.

New Jersey Gov. Thomas H. Kean, a Republican, will appoint a successor to Williams, who had a year remaining in his fourth term. Kean likely will name a Republican, which would give the GOP a 54-to-46 majority in the Senate.

Rep. Millicent Fenwick (R-N.J.) and Jeffrey Bell, a former Reagan speechwriter who ran unsuccessfully for the Senate in 1978, are announced candidates for the Republican nomination.

But it is unclear if the newly elected Kean will pick one of them, name a caretaker or wait until the party primary and appoint the winner. Rep. James A. Courter, Kean's campaign chairman last year, is known to be interested in the Senate post.

Although sources said Williams told at least one Senate colleague Wednesday that he intended to resign, and earlier that day his staff had requested a draft copy of a letter of resignation, the senator insisted he had not made a decision until about 11:30 a.m. yesterday.

Democratic colleagues had been pressuring Williams to resign for days. But his decision wasn't tipped on the floor yesterday until Sen. Daniel K. Inouye (D-Hawaii), his chief defender, turned to Williams in the chamber and assured him that "Abscam will be investigated."

"My good friend, I bid you farewell and Godspeed," said Inouye, a World War II hero and one of the Senate's most respected members. "To you and Jeanette, God bless you."

Majority Whip Stevens added, "My dear friend, I can only state my sorrow at what is going to happen now."

Williams, who had argued his own defense on the Senate floor for 5 1/2 hours over two days, spoke for 21 minutes yesterday. As before, he spent most of the time declaring his innocence and condemning the government's conduct.

"If I had believed for a moment that my resignation would prevent this distinguished body from becoming involved in the vile history of Abscam, I would have resigned long ago and spared all of us this pain," he said.

Williams was convicted of agreeing to use his office in exchange for a hidden share in a mining venture that was to have been financed by a $100 million loan from an undercover agent posing as an Arab sheik. He was sentenced to three years in prison and fined $50,000.

Yesterday he looked relaxed, almost buoyant, as if a huge burden had been lifted from his shoulders.

"I feel no stain," he said as he sat for his final time on the floor. "I feel strengthened. Thank you, all of you."

Four short speeches--full of praise and sorrow for Williams--followed. Minority Leader Robert C. Byrd (D-W. Va.) said, "This is a sad moment for the Senate." Howell Heflin (R-Ala.), vice chairman of the Ethics Committee, which last summer unanimously recommended his expulsion for "ethically repugnant" conduct, said, "The American people are stronger because we had this debate."

Only Ethics Committee Chairman Malcolm Wallop (R-Wyo.) entered a note of reality. "There is no doubt about what the Senate was prepared to do" had Williams not resigned, he said.

When it finally ended, senators and Senate aides lined up for 15 minutes to shake Williams' hand. "I'm sure glad this day is over," Sen. David Pryor (D-Ark.) said later.

Williams' staunchest supporters, Inouye and Minority Whip Cranston, sponsor of a resolution to censure rather than expel him, began urging Williams to resign Tuesday after Sen. Thomas F. Eagleton (D-Mo.), whom Williams' supporters had hoped would joined them, gave a devasting floor speech.

Williams was shaken by it, and afterward spent 20 minutes talking with Inouye on the Senate floor. That night, Inouye, according to Senate sources, called Majority Leader Howard H. Baker Jr. (R-Tenn.) to inform him that Williams was being urged to resign.

A vote on censure was postponed Wednesday after Williams told Inouye he might resign, sources said. But that night, the Rev. Carl McIntire, a radio evangelist who had befriended Williams, said that he and Jeanette Williams had urged the beleaguered senator "to keep fighting."

"My feeling was he should go right down the road and be a martyr and wear the martyr's robe," McIntire said. "He would go down in history because no one in history had ever been expelled under these circumstances."

In its history, the Senate has expelled only 15 members, all but one for treason or disloyalty during the Civil War. The last to be expelled was Jesse D. Bright of Indiana, in 1862, for writing a letter to Confederate President Jefferson Davis introducing a friend with firearms to sell.

Four other senators--two in this century--resigned under a cloud. Joseph R. Burton, a Kansas Republican, convicted of accepting illegal payments to find out if the Post Office Department was investigating a company, quit in 1906. In 1922, Truman H. Newberry, a Michigan Republican, resigned, saying he felt vindicated of charges of election fraud because his conviction had been overturned by the Supreme Court.

Williams, even if jailed, is eligible to receive an annual pension of about $45,000, Senate floor privileges, and use of its gym, barber shop, library, dining room and parking lot. He would have been entitled to these same benefits even if expelled.