Defense Secretary Caspar W. Weinberger said yesterday that some Iranian gunboats in the Persian Gulf may have been equipped with American-made Stinger missiles, the first official U.S. indication that Iran has obtained the sophisticated surface-to-air weapons.

The Stingers are reported by The London Sunday Times and U.S. government sources to have been sold to Iran by one of the seven Afghan rebel groups to which the United States has been secretly sending hundreds of the antiaircraft weapons over the past year. Pentagon officials said yesterday they do not know how the Iranians obtained the Stingers and said they are investigating.

Pentagon sources said U.S. forces found "pieces of a Stinger," including batteries and packing, aboard two bullet-riddled gunboats retrieved after Army assault helicopters attacked four Iranian vessels in response to shots fired at one of the U.S. helicopters Thursday night.

Weinberger characterized the attack as self-defense and warned that when gulf shipping "is interfered with, then we teach lessons or we take the necessary steps to make sure that it isn't interfered with."

"We have repeatedly communicated to the Iranian government the seriousness with which we view such Iranian interference with our forces in the gulf operating in international waters and airspace," State Department spokesman Charles E. Redman said yesterday.

"We are following up after this most recent incident and warning the government of Iran that it bears the consequences of such actions," Redman added.

Iranian radio reported yesterday that the crew on one of the speedboats used a Stinger to shoot down a U.S. helicopter after the attack on the gunboats. The Pentagon said it has received "absolutely no reports" of such an attack and said it has received no notification that any U.S. helicopters have been lost.

Three Army special operations helicopters fired at four Iranian gunboats after the Iranians shot at one of the American helicopters late Thursday night, Pentagon sources said.

Weinberger said that U.S. forces sank a 43-foot Swedish-made Boghammer patrol boat and yesterday captured two smaller vessels, which he identified as Boston Whalers, that were severely damaged. He said a fourth vessel, believed to be a Corvette speedboat, escaped the attack.

U.S. officials said six Iranians were rescued after the attack, two of whom later died. Iranian officials said they believe 12 crew members were aboard the three craft.

The attack provoked a strong reaction from Iranian officials yesterday. Iran's U.N. Ambassador Said Rajaie Khorassani said, "I think it's a declaration of war by the United States against Iran, that's definite." He also alleged that U.S. helicopters, not the Iranian gunboats operating in international waters off Farsi Island, provoked the attack.

Senate leaders, debating the 1973 War Powers Resolution, yesterday proposed sharply scaled-back constraints on the Reagan administration's tanker-escort operations in the gulf, but the White House and the Pentagon reiterated that they do not believe the resolution should apply to the gulf mission.

During a speech to a conference at the U.S. Information Agency here yesterday, Weinberger revealed that the Iranians may now be using the shoulder-fired Stinger missiles. He said that the two Iranian boats retrieved by U.S. forces "are little. . . boats that have machine guns and sometimes Stinger equipment."

Sen. Dennis DeConcini (D-Ariz.), the member of the Senate Select Committee on Intelligence who has been most concerned about Stingers falling into the hands of terrorists, said Weinberger's report, if true, is "the worst scenario" that could happen in the gulf.

"Now one of our worst enemies may have one of our best weapons in one of the most volatile regions of the world," DeConcini said. "This is something I warned the president about almost two years ago," he said, referring to his warnings about Stingers being supplied by the Central Intelligence Agency to Afghan rebels.

The Stingers have proved highly effective in the hands of Afghan rebels, who recently were reported to be shooting down Afghan and Soviet aircraft, particularly helicopters, at a rate of one or more a day.

U.S. military experts said American helicopters, rather than planes, are likely to be threatened the most by Stingers in the Persian Gulf.

Just two days ago the administration was forced to abandon plans to provide Stingers to the Persian Gulf shiekhdom of Bahrain, a key ally for U.S. forces, because of strong opposition in the Senate. The cancellation of the Stinger sale to Bahrain was part of a deal reached with the Senate over a $1 billion arms package to Saudi Arabia.

According to DeConcini, the administration also was planning to provide the missiles to two other Arab states on the gulf, Oman and the United Arab Emirates, which also have been providing support for U.S. forces involved in escorting reflagged Kuwaiti oil tankers.

It is unclear whether the administration will still press to provide Stingers to Oman and the United Arab Emirates in light of the strong congressional opposition to their sale to Bahrain.

An aide to DeConcini said yesterday that the senator plans to introduce legislation that would require the administration to obtain approval of Congress for sale of Stingers to any of the Arab gulf states.

The London Sunday Times on Sept. 20 reported that the Younis Khalis' Islamic Party, perhaps the most fundamentalist of the seven Afghan rebel factions with close ties to the Iranian regime, had sold the Stingers to the Iranians. It said that two local Islamic Party commanders in western Afghanistan sold at least 16 Stingers to the Iranians for $1 million out of a stock of 32 they had received through the covert U.S. military aid program to the Afghan anticommunist resistance.

The story said the two commanders denied selling the Stingers and claimed instead the weapons had been "captured" by Iranians operating inside Afghanistan.

The Middle East Economic Digest reported in its Oct. 3 edition that the Iranian military had put some of the Stingers on display during "war week" parades in late September.