There was a time when Richard M. Nixon, president of the United States, was a man on the run, and Edward I. Koch, a liberal Democratic congressman from New York, was a man after him.

Tonight, in a Republican fund-raiser, Koch -- who last week received the endorsement of even the Republican Party in his mayoral reelection bid -- said that sure, if he were to see Nixon at the party, he would shake hands with him.

"President Nixon is someone I sought to impeach and rightly so; I sought to take away his pension and rightly so . . . . He suffered and quite correctly," said the mayor, who likes to pass judgment, most often approving, on his actions.

"But, if he were here, do you think I shouldn't shake hands with him? Shaking hands is a social grace; it doesn't confer affection, or endorsement for anyone . . . though I have no intention, I give you my word of honor, that he will be a commissioner in my administration."

The former president, for his part, pressed by a mob of reporters to discuss Koch, endorsed the mayor.

"I understand he's a shoo-in," Nixon said, "and he should be."

Politics can stir up many interesting friendships as years go by, and tonight's $200-a-plate New York State Republican fund-raiser at Lincoln Center was no exception.

Rep. Jack Kemp and Richard M. Rosenbaum, who are being mentioned as gubernatorial posibilities, strolled arm in arm. In addition to Sixon, Secretary of Labor Raymond J. Donovan and Henry A. Kissinger, many political rivals were in the room.

Still, nothing quite matched Koch's first-ever appearance at a Republican fund-raiser.

"There are no deals here," the mayor hollered to television crews as he arrived. He reportedly had promised to help the party erase it $750,000 debt if it endorsed him.

"They're endorsing me. Don't you think I should help them help me get elected?" he asked.

That is somewhat like buying the nomination, is it not, a reporter asked.

"Riiii-----dik!----u---luuuus!!!!!" the mayor said.

Koch denied, as did members of his staff, that his arrival and departure (he stayed 20 minutes) had been timed so he could avoid encountering Nixon and having to shake his hand.

When Nixon arrived, he was mobbed. It was difficult to make out precisely what was said, but the essence seemed to be that Nixon thought he should support President Reagan; he was not running for mayor of Saddle River, N.J., to which he is considering moving, and he is not planning to run for the U.S. Senate.

"We need a new diplomatic initiative in the Middle East -- in the long term, Israel's security cannot be guaranteed by attacking its enemies," said Nixon, who added that he misses baseball during the current player strike.

Nixon's entrance at the fund-raiser was like that of royalty. Republicans of all ages, predominantly middle and upward, stood in a receiving line for half an hour to shake his hand. Many sought autographs.

One fellow, Edward Phillips, a "Nixon Republican and proud of it," brough along a Christmas card Nixon had sent him from the White House, in happier times, circa 1973. "I sent one to Carter, and I didn't even get one back, which goes to show," Phillips said.

Contentment was not entirely rife in the GOP, of course. There had been reports a few weeks ago that some Republicans, notably Sen. Warren Rudman (N.H.), considered it inappropriate to invite Nixon. Last week, Rep. Bill Green (N.Y.) said the invitation was "not judicious."

At the fund-raiser, there were fierce denials on that subject.

"It broke me up," GOP state party leader George Clark said sarcastically of Rudman's comment. "Who's Rudman?" he asked.

More polite and even philosophical on the presence of Nixon was newly elected Sen. Alfonse M. D'Amato (N.Y.), who has, in his time, suffered similar nasty little political slings.

"I don't know how many saints we have walkin' around," he said, summing up neatly the reality of political life.