The Senate, by 81 to 4, gave final congressional approval yesterday to a bill that will make it a crime to disclose the names of U.S. intelligence agents even if the information is obtained from public records.

The measure, dubbed the Intelligence Identities Protection Act, goes to President Reagan who has endorsed it heartily. It sailed through the House last week by a vote of 315 to 32.

The bill imposes maximum penalties of 10 years in prison and fines of $50,000 for unauthorized disclosures by past or present government employes who have had access to classified information.

The bill provides that individuals outside the government, such as journalists and scholars, could be sentenced to three years in prison and fined $15,000 if they "name names" in the course of "a pattern of activities intended to identify and expose covert agents" and if they have "reason to believe that such activities would impair or impede the foreign intelligence activities of the United States."

The conference committee that reconciled differing House and Senate versions last month sought to blunt charges of unconstitutionality with an explanatory conference report stating that the bill is not meant to apply to "news media reporting of intelligence failures or abuses" or other undertakings such as "academic studies of U.S. government policies and programs."

The conferees said they meant to punish only "those engaged in the pernicious business of naming names" of U.S. intelligence agents with the avowed aim of "blowing" their covers and destroying their effectiveness. The impetus for the bill grew out of the activities of CIA renegade Philip Agee and like-minded publications such as the Covert Action Information Bulletin.

The prime mover of the bill in the Senate, John H. Chafee (R-R.I.)., said yesterday that he believed "we have tailored it so that we are able to walk that narrow boundary" between hitting the intended targets while protecting the First Amendment right of others.

Senate Intelligence Committee Chairman Barry Goldwater (R-Ariz.) hailed it as "long, long overdue" and predicted that it "will stop intelligence sources from refusing to cooperate with us for fear their names will be exposed."

A dwindling number of opponents contended it was still unconstitutional. Among them was Sen. Daniel Patrick Moynihan (D-N.Y.) who said his no vote was "perhaps the most difficult in my five years in this body." But he said he did not see how the conference report would hem in the sweeping language of the bill or prevent prosecutions for merely "negligent" conduct.

Both Senate and House had abandoned a malicious intent standard for the "reason to believe" rule. "It now appears," Moynihan protested, "that we will soon have a law which, while making it easier to convict scoundrels, will chill the exercise of First Amendment rights."

Also voting against the bill were Sen. Charles McC. Mathias (R-Md.), Joseph R. Biden Jr. (D-Del.) and Gary Hart (D-Colo.).