As the Liberty passed the desert town of El Arish, it was being closely watched. About 4,000ft above was an Israeli reconnaissance aircraft. At 6.05am, the observer on the plane reported back to Israeli naval headquarters: "What we could see were the letters written on that ship and we gave these letters to ground control," he said. The letters were "GTR-5" - the Liberty's identification. "GTR" stood for "General Technical Research" - a cover designation for the National Security Agency (NSA)'s fleet of spy ships.

The Liberty was in dangerous waters at a dangerous time. The six-day war, in which Israeli air and ground forces launched a massive attack on Egypt, Syria and Jordan, was raging. Fearing involvement in a Middle East war, the US joint chiefs of staff needed rapid intelligence on the ground situation in Egypt. Ships were considered the best option for the job. They could sail relatively close and pick up the most important signals. Also, unlike aircraft, they could remain on station for weeks at a time, eavesdropping, locating transmitters, and analysing the intelligence. And so the Liberty, which was large, fast and had been stationed relatively close on the Ivory Coast, had been ordered in.

Throughout the morning, the ship sailed on, with reconnaissance repeated at approximately 30-minute intervals. At one point, an Israeli air force Noratlas Nord 2501 circled the ship and headed back towards the Sinai. "It had a big Star of David on it and it was flying just a little bit above our mast," recalled crew member Larry Weaver. "I was actually able to wave to the co-pilot. He waved back and actually smiled at me - I could see him that well. There's no question about it. They had seen the ship's markings and the American flag. They could damn near see my rank. The underway flag was definitely flying, especially when you're that close to a war zone."

By 9.50am, the minaret at El Arish could be seen with the naked eye like a solitary mast in a sea of sand. Although no one on the ship knew it at the time, the Liberty had suddenly trespassed into a private horror. At that very moment, near the minaret, Israeli forces were engaged in a criminal slaughter.

Three days after Israel had launched the six- day war, Egyptian prisoners in the Sinai had become a nuisance. There was no place to house them, not enough Israelis to watch them, and few vehicles to transport them to prison camps. But there was another way to deal with them.

As the Liberty sat within eyeshot of El Arish, eavesdropping on surrounding communications, Israeli soldiers turned the town into a slaughterhouse, systematically butchering their prisoners. An eyewitness recounted how in the shadow of the El Arish mosque, they lined up about 60 unarmed Egyptian prisoners, hands tied behind their backs, and then opened fire with machine guns until the pale desert sand turned red.

This and other war crimes were just some of the secrets Israel had sought to conceal since the start of the conflict. An essential element in the Israeli battle plan seemed to have been to hide much of the war behind a carefully constructed curtain of lies: lies about the Egyptian threat, lies about who started the war, lies to the US president, lies to the UN Security Council, lies to the press, lies to the public. Thus, as the American naval historian Dr Richard K Smith noted, "any instrument which sought to penetrate this smoke screen so carefully thrown around the normal 'fog of war' would have to be frustrated".

Into this sea of deception and slaughter sailed the USS Liberty, an enormous spy factory loaded with the latest eavesdropping gear.

About noon, as the Liberty was again in sight of El Arish, and while the massacres were taking place, an army commander there reported that a ship was shelling them from the sea. But that was impossible. The only ship in the vicinity was the Liberty, and she was eavesdropping, not shooting. As any observer would have recognised, the ship was a tired old second world war vessel crawling with antennae, and unthreatening to anyone - unless it was their secrets, not their lives, they wanted to protect.

By then the Israeli navy and air force had conducted more than six hours of close surveillance of the Liberty off the Sinai and must have positively identified it as an American electronic spy ship. They knew she was the only military ship in the area. Nevertheless, the order was given to kill her and at 12.05pm, three motor torpedo boats from the port of Ashdod, about 50 miles away, departed. Israeli air force fighters, loaded with 50mm cannon ammunition, rockets and napalm, followed.

Without warning, the Israeli jets - swept-wing Dassault Mirage IIICs - struck. On board Liberty, Lieutenant Painter observed that the aircraft had "absolutely no markings", their identity unclear. He then attempted to reach the men manning the gun mounts, but it was too late. "I was trying to contact these two kids," he recalled, "and I saw them both; well, I didn't exactly see them as such. They were blown apart, but I saw the whole area go up in smoke and scattered metal. At about the same time, the aircraft strafed the bridge area. The quarter-master, Petty Officer Third Class Pollard, was standing right next to me, and he was hit."

The Mirages raked the ship from bow to stern with armour-piercing lead. A bomb exploded near the whaleboat aft of the bridge, and those in the pilothouse and the bridge were thrown from their feet. Commander William L McGonagle grabbed for the engine order annunciator and rang up all ahead flank.

In the communications spaces, radiomen James Halman and Joseph Ward had patched together enough equipment and broken antennae to get a distress call off to the Sixth Fleet, despite intense jamming by the Israelis. "Any station, this is Rockstar," Halman shouted, using the Liberty's voice call sign. "We are under attack by unidentified jet aircraft and require immediate assistance."

"Great, wonderful, she's burning, she's burning," said an Israeli pilot.

At 2.09pm, the aircraft carrier USS Saratoga, operating near Crete, acknowledged Liberty's cry for help. "I am standing by for further traffic," it signalled.

After taking out the gun mounts, the Israeli fighter pilots turned their attention to the antennae so the ship could not call for help or pick up any more revealing interceptions. Then the planes attacked the bridge, killing instantly the ship's executive officer. With the Liberty now deaf, blind, and silenced, unable to call for help or move, the Israeli pilots proceeded to kill her. Designed to punch holes in the toughest tanks, their shells tore through the Liberty's steel plating like hot nails through butter, exploding into jagged bits of shrapnel and butchering men deep in their living quarters.

As the slaughter continued, neither the Israelis nor the Liberty crew had any idea that witnesses were present high above. Until now, that is. According to information, interviews and documents obtained, for nearly 35 years the NSA has hidden the fact that one of its planes - a Navy EC-121 ferret - was overhead at the time of the incident, eavesdropping on what was going on below. The interceptions from that plane, which answer some of the key questions about the attack, are among the NSA's deepest secrets.

The ferret had taken off from Athens for its regular patrol of the eastern Mediterranean, and at about the time that the air attack was getting underway, Navy Chief Petty Officer Marvin Nowicki heard one of the other Hebrew linguists on the plane excitedly trying to get his attention on the secure intercom. "Hey, chief," he shouted, "I've got really odd activity on UHF. They mentioned an American flag. I don't know what's going on." Nowicki asked the linguist for the frequency and "rolled up to it". "Sure as the devil," said Nowicki, "Israeli aircraft were completing an attack on some object. I alerted the evaluator, giving him sparse details, adding that we had no idea what was taking place."

Deep down in Liberty, Terry McFarland, head encased in earphones, was vaguely aware of flickers of light coming through the bulkhead. He had no idea that they were armour-piercing tracer bullets slicing through the ship's skin. Larry Weaver had run to his general quarters station but it was located on an old helicopter pad that left him exposed and vulnerable. He grabbed a dazed shipmate and pushed him into a safe corner. "I said, 'Fred, stay here, you've just got to because he's coming up the centre'," Weaver recalled. "I got in the foetal position," he said, "and before I closed my eyes I looked up and I saw the American flag and that was the last thing I saw before I was hit. I closed my eyes, just waiting for hell's horror to hit me. And I was hit by rocket and cannon fire that blew two and a half feet of my colon out and I received over 100 shrapnel wounds. It blew me up in the air about four and a half, five feet. And just blood everywhere."

Stan White raced through the sick bay for the enclosed NSA spaces. "Torn and mutilated bodies were everywhere," he said. "Horrible sight!"

As soon as the Mirages pulled away, they were replaced by Super Mystere fighters which raked the ship. A later analysis would show 821 separate hits on the hull and superstructure. Now, in addition to rocket, cannon, and machine-gun fire, the Mysteres attacked with 1,000lb bombs and napalm. Deafening explosions tore through the ship and the bridge disappeared in an orange-and-black ball. Lying wounded by shrapnel, his blood draining into his shoe, was Commander McGonagle. Seconds later the fighters were back. Flesh fused with iron as more strafing was followed by more rockets, followed by napalm.

As the last fighter departed, having emptied out its onboard armoury, turning the Liberty's hull into a flaming mass of grey Swiss cheese, sailors lifted mutilated shipmates on to makeshift stretchers of pipe frame and chicken wire. Damage control crews pushed through passageways of suffocating smoke and blistering heat, and the chief petty officer's lounge was converted into a macabre sea of blood-soaked mattresses and shattered bodies.

After landing back at Athens airport, Nowicki and the intercept crew were brought directly to the processing centre. "By the time we arrived at the USA-512J compound," he said, "collateral reports were coming in to the station about the attack on the USS Liberty. The NSA civilians took our tapes and began transcribing. It was pretty clear that Israeli aircraft and motor torpedo boats attacked a ship in the east Med. Although the attackers never gave a name or a hull number, the ship was identified as flying an American flag. We logically concluded that the ship was the USS Liberty."

At 2.50pm (Liberty time), 50 minutes after the first shells tore into the ship and as the attack was still going on, the aircraft carrier USS America, cruising near Crete, was ordered to launch four armed A-4 Skyhawks. At the same time, the carrier USS Saratoga was also told to send four armed A-1 attack planes to defend the ship. "Sending aircraft to cover you," the Sixth Fleet told the Liberty at 3:05pm (9.05am in Washington). "Surface units on the way."

At that moment in Washington, President Johnson was at his desk, on the phone, alternately shouting at congressional leaders and coaxing them to support his position on several pieces of pending legislation. But four minutes later he was interrupted by Walt Rostow, national security adviser, on the other line. "The Liberty has been torpedoed in the Mediterranean," Rostow told Johnson excitedly.

The NSA's worst fears had come true. "After considerations of personnel safety," said deputy director Tordella, "one of my immediate concerns, considering the depth of the water and the distance of the ship off shore, had to do with the classified materials on board." Tordella got on the phone to the Joint Reconnaissance Centre (JCS) and spoke to the deputy director, a Navy captain named Vineyard. "I expressed my concern that the written material be burned if at all possible, and that the electronic equipment be salvaged if that were possible," he said.

But Tordella was not prepared for what he heard. According to NSA documents - classified top secret- he was told that some senior officials in Washington wanted above all to protect Israel from embarrassment. "Captain Vineyard had mentioned during this conversation," wrote Tordella, "that consideration was then being given by some unnamed Washington authorities to sink[ing] the Liberty in order that newspaper men would be unable to photograph her and thus inflame public opinion against the Israelis. I made an impolite comment about the idea." Almost immediately, Tordella wrote a memorandum for the record, describing the conversation, and then locked it away.

A cover story for the Liberty was then quickly devised. "She was a communications research ship that was diverted from her research assignment," it said, "to provide improved communication-relay links with the several US embassies around the entire Mediterranean during the current troubles."

On the Liberty, black smoke was still escaping through more than 800 holes in the hull, and the effort to hush up the incident had already begun. Within hours of the attack, which left 34 men dead and two-thirds of the rest of the crew wounded, Israel asked President Johnson to quietly bury the incident. "Embassy Tel Aviv," said a highly secret, very limited distribution message to the state department, "urged de-emphasis on publicity since proximity of vessel to scene of conflict was fuel for Arab suspicions that the US was aiding Israel." Shortly thereafter, a total news ban was ordered by the Pentagon. No one in the field was allowed to say anything about the attack. All information was to come only from a few senior Washington officials.

Later that morning, Johnson took the unusual step of ordering the JCS to recall its fighters while the Liberty still lay smouldering, sinking, fearful of another attack and with its decks covered with the dead, dying and wounded. On board the flagship of the Sixth Fleet, Rear Admiral Lawrence R Geis, who commanded the carrier force in the Mediterranean, was angry and puzzled at the recall and protested to the secretary of defence, Robert S McNamara.

Geis was shocked by what he heard next. "President Lyndon Johnson came on with a comment that he didn't care if the ship sunk, he would not embarrass his allies." Geis told Lieutenant Commander David Lewis, head of the NSA group on the Liberty, about the comment but asked him to keep it secret until after Geis died. It was a promise that Lewis kept.

In the days following the attack, the Israeli government gave the US government a classified report that attempted to justify the claim that the attack was a mistake. On the basis of that same report, an Israeli court of inquiry completely exonerated the government and all those involved. No one was ever court-martialled, reduced in rank or even reprimanded. On the contrary, Israel chose instead to honour motor torpedo boat 203, which fired the deadly torpedo at the Liberty. The ship's wheel and bell were placed on prominent display at the naval museum, among the maritime artefacts of which the Israeli navy was most proud.

Despite the overwhelming evidence that Israel had attacked the ship and killed the American servicemen deliberately, the Johnson administration and Congress covered up the entire incident. Johnson was planning to run for president the following year and needed the support of pro-Israel voters.

A mistake or mass murder? It was a question Congress never bothered to address in public hearings at the time. Among those who have long called for an in-depth congressional investigation is Admiral Thomas Moorer, who went on to become chairman of the joint chiefs of staff. "Congress to this day," he said, "has failed to hold formal hearings for the record on the Liberty affair. This is unprecedented and a national disgrace." Perhaps it is not too late.

 Extracted from Body of Secrets by James Bamford, published by Century at £20 © 2001 James Bamford