A senior Spanish official today displayed photographs of the communication tower of the prime minister's official residence in Madrid that he said had been taken by two U.S. diplomats who were "caught red-handed" on Jan. 28 by the residence's security staff.

The official called the incident "an unbelievably clumsy act of espionage" and said that one of the two diplomats injured a finger belatedly attempting to open the camera and expose the film as the Spanish security agents grabbed them.

He also ridiculed the Americans' alleged efforts to surreptitiously photograph the tower at the Moncloa Palace, noting that when President Reagan visits Prime Minister Felipe Gonzalez in May "there will be scores of U.S. photographers here in the Moncloa Palace and they will be able to take all the pictures they want of the antennae."

"There must be 50 different ways in which our antennae can be photographed and we would be none the wiser," the official said.

Photographs of the palace are frequently published and the government's ire seemed directed more at the manner in which the Americans allegedly acted and their focusing on the communications tower in a way that suggested an intelligence mission.

In an apparent attempt to poke fun at the Americans, Liberacion, a left-wing Madrid newspaper, published a photograph Sunday of the communications tower taken by one of the paper's staff photographers.

While the Spanish government appeared prepared, at least publicly, to shrug off the incident, some officials privately expressed concern about what they saw as U.S. willingness to risk a serious diplomatic incident less than three months before Reagan's arrival as part of a European tour.

The two Americans -- Dennis E. McMahan and John F. Massey, both attached to the U.S. Embassy here -- have since returned to the United States and the embassy refused to comment on the incident or the account given today by the Spanish official, who spoke on the condition that he not be identified.

According to his account, the two men were spotted by a sentry during the lunch hour on Jan. 28 as they approached the Moncloa Palace across a strip of waste land.

McMahan, listed as a second secretary in the embassy's political section, reportedly was photographing the palace's 90-foot-high red-and-white communications tower with a long-range camera held at waist level. Guards were sent out to investigate.

The official said McMahan had opened the camera and attempted to expose the whole film when he and Massey were approached from behind by members of the security staff. In a brief struggle a Spanish officer secured the camera, slightly injuring one of McMahan's fingers, the official said.

Both diplomats claimed they were tourists taking photographs of buildings of architectural note in the vicinity of the premier's residence, according to the Spanish official. But he noted that they had not photographed a futuristic building nearby that "has won Spain's top architectural prize."

He showed photocopies of diplomatic residence cards issued by the Foreign Ministry that he said the men were carrying. They identified McMahan as a member of the U.S. Embassy staff and Massey as attached to the embassy, employed in a civilian capacity at the joint U.S.-Spanish air base at Torrejon de Ardoz, east of Madrid.

The film was developed in Gonzalez's own private dark room, the official said, to establish rapidly what the diplomats were doing. It showed that they had taken one photograph of an approach road to the residence and six, all from the same angle, of the communications tower.

Gonzalez was informed of the incident, the official said, and ordered that U.S. Ambassador Thomas O. Enders be told.

Both men were released after a quarter of an hour. Later Spanish intelligence officials said the photographs appeared to be an attempt to learn radio frequencies used by Gonzalez's office. The foreign minister then asked Enders to have both diplomats recalled to the United States.

Some sources have speculated that the diplomats were investigating the import and reexport of sophisticated American technology to Soviet Bloc countries, but the Spanish official rejected this explanation. He called it, rather, a case of "spies being caught red-handed."

The case, meanwhile, has fascinated the Spanish public and damaged the standing of the U.S. government in some circles here.

The conservative opposition, which is the most supportive of Washington in Spain, said it will ask Gonzalez and his Socialist government to explain the incident in parliament. The Communist Party has urged that Reagan be asked not to visit Spain.

The influential Madrid newspaper El Pais said that at the very least the affair had proved a disservice to the pro-NATO stand of Gonzalez's government. He plans a referendum next year to gain endorsement of continued membership in NATO.