The ghosts of Nassau County came back to haunt Alfonse D'Amato today.

D'Amato, one-time chief executive of this sprawling Long Island town of 800,000, is now a U.S. senator, but his roots in one of the nation's more infamous political machines were on display as he testified about his role in the local patronage system during the 1970s.

Volunteering at one point that "I may have had blinders on," D'Amato said he had viewed most contributions to the GOP by local government employes as voluntary.

The senator testified in a federal class-action suit that several Nassau County and Hempstead government workers filed against the Nassau County Republican Committee, Nassau County and the town of Hempstead, seeking to recover $5 million in political contributions. To be hired, promoted or to receive raises, the employes allege, they were forced to contribute 1 percent of their salaries to the local GOP.

"If we win here, a lot of political machines around the country are going to be concerned about having to disgorge a lot of contributions," said Burt Neuborne, legal director of the American Civil Liberties Union and the plaintiffs' court-appointed lawyer.

The trial began three weeks ago. The first evidence introduced was a 1971 letter from D'Amato to a top aide of Nassau County GOP chief Joseph M. Margiotta, seeking a raise for a garbageman and enclosing a contribution.

"I have spoken to Mr. Margiotta," the letter said, "and he has indicated to me that the raise for Mr. Marcus of the Sanitation Department would be approved if he Marcus took care of the 1 percent. Accordingly, please find check for $75 from the Island Park Republican Committeemen's Council."

D'Amato testified today that the county committee, which he headed, had paid Marcus' 1 percent contribution as an act of charity because the man had been ill and was in financial straits.

Neuborne said D'Amato's testimony showed that he "was up to his neck in the system." Margiotta was convicted four years ago of mail fraud and extortion in an insurance kickback scheme and served 14 months in prison.

D'Amato, who is up for reelection next year, said in a news conference today that while Democrats may try to use the issue against him, as they did in 1980, "most fair-minded people" would understand his actions.

Of the 1 percent contributions, he testified, "Obviously it was a factor" in giving raises and promotions to government employes. But he said the 1 percent "guide" was established to keep the Republican Party "successful."

He had supported that goal, he said, after being fired as assistant county attorney when Democrats took control for eight years beginning in 1961.

D'Amato said he and other government workers resolved to give 1 percent of their salaries to the GOP because "we were frightened" that the Democrats might regain power.

In the news conference, D'Amato acknowledged that there were "certain abuses" during the '70s. "It was a mindset," he said. "The climate of the times was 'To the victor belongs the spoils' . . . . In retrospect, I can appreciate that some people felt an undue force" in being asked to contribute to the party. Those people "should be repaid," he said.

The Republican Party, still largely controlled by Italian Americans, remains dominant in Hempstead, more than half of whose 800,000 inhabitants are black.

"Fresh out of high school, I joined the Republican Party," Mike Johnson, 25, a black cabdriver, said in an interview. "My teachers told me, to get a job in Nassau County you have to be Republican, and it's still that way . . . "