He prepared briefs for Dick Cheney, when Cheney was at the Pentagon, for the upper echelons of the CIA and even for the Oval Office. But when he uncovered a political scandal - a conspiracy to enable a rogue nation to get the nuclear bomb - he found himself a marked man.

In the late 80s, in the course of tracking down smugglers of WMD components, Barlow uncovered reams of material that related to Pakistan. It was known the Islamic Republic had been covertly striving to acquire nuclear weapons since India's explosion of a device in 1974 and the prospect terrified the west - especially given the instability of a nation that had had three military coups in less than 30 years . Straddling deep ethnic, religious and political fault-lines, it was also a country regularly rocked by inter-communal violence. "Pakistan was the kind of place where technology could slip out of control," Barlow says.

He soon discovered, however, that senior officials in government were taking quite the opposite view: they were breaking US and international non-proliferation protocols to shelter Pakistan's ambitions and even sell it banned WMD technology. In the closing years of the cold war, Pakistan was considered to have great strategic importance. It provided Washington with a springboard into neighbouring Afghanistan - a route for passing US weapons and cash to the mujahideen, who were battling to oust the Soviet army that had invaded in 1979. Barlow says, "We had to buddy-up to regimes we didn't see eye-to-eye with, but I could not believe we would actually give Pakistan the bomb.

How could any US administration set such short-term gains against the long-term safety of the world?" Next he discovered that the Pentagon was preparing to sell Pakistan jet fighters that could be used to drop a nuclear bomb.

Barlow was relentless in exposing what he saw as US complicity, and in the end he was sacked and smeared as disloyal, mad, a drunk and a philanderer. If he had been listened to, many believe Pakistan might never have got its nuclear bomb; south Asia might not have been pitched into three near-nuclear conflagrations; and the nuclear weapons programmes of Iran, Libya and North Korea - which British and American intelligence now acknowledge were all secretly enabled by Pakistan - would never have got off the ground. "None of this need have happened," Robert Gallucci, special adviser on WMD to both Clinton and George W Bush, told us. "The vanquishing of Barlow and the erasing of his case kicked off a chain of events that led to all the nuclear-tinged stand-offs we face today. Pakistan is the number one threat to the world, and if it all goes off - a nuclear bomb in a US or European city- I'm sure we will find ourselves looking in Pakistan's direction."

US aid to Pakistan tapered off when the Soviet Union withdrew from Afghanistan. Dejected and impoverished, in 1987 Pakistan's ruling military responded by selling its nuclear hardware and know-how for cash, something that would have been obvious to all if the intelligence had been properly analysed. "But the George HW Bush administration was not looking at Pakistan," Barlow says. "It had new crises to deal with in the Persian Gulf where Saddam Hussein had invaded Kuwait."

As the first Gulf war came to an end with no regime change in Iraq, a group of neoconservatives led by Paul Wolfowitz, Dick Cheney, Lewis "Scooter" Libby and Donald Rumsfeld were already lobbying to finish what that campaign had started and dislodge Saddam. Even as the CIA amassed evidence showing that Pakistan, a state that sponsored Islamist terrorism and made its money by selling proscribed WMD technology, was the number one threat, they earmarked Iraq as the chief target.

When these neocons came to power in 2001, under President George W Bush, Pakistan was indemnified again, this time in return for signing up to the "war on terror". Condoleezza Rice backed the line, as did Rumsfeld, too. Pakistan, although suspected by all of them to be at the epicentre of global instability, was hailed as a friend. All energies were devoted to building up the case against Iraq.

It is only now, amid the recriminations about the war in Iraq and reassessments of where the real danger lies, that Barlow - the despised bringer of bad news about Pakistan - is finally to get a hearing. More than 20 years after this saga began, his case, filed on Capitol Hill, is coming to court later this month. His lawyers are seeking millions of dollars in compensation for Barlow as well as the reinstatement of his $80,000 a year government pension. Evidence will highlight what happened when ideologues took control of intelligence in three separate US administrations - those of Reagan, and of the two Bushes - and how a CIA analyst who would not give up his pursuit for the truth became a fall guy.

Born in Upper Manhattan, New York, the son of an army surgeon, Barlow went to an Ivy League feeder school before attending Western Washington University on America's northwest tip. Even then he was an idealist and an internationalist, obsessively following world events. He majored in political science, and his thesis was on counter-proliferation intelligence; he was concerned that the burgeoning black markets in nuclear weapons technology threatened peace in the west. "I got my material from newspapers and books," he recalls. "I went to congressional hearings in Washington and discovered that there was tonnes of intelligence about countries procuring nuclear materials." After graduation in 1981, shortly after Reagan became president - avowedly committed to the non proliferation of nuclear weapons - Barlow won an internship at the State Department's Arms Control and Disarmament Agency (ACDA), which had been established by John F Kennedy in the 60s.

At first Barlow thought he was helping safeguard the world. "I just loved it," he says. His focus from the start was Pakistan, at the time suspected of clandestinely seeking nuclear weapons in a programme initiated by Zulfikar Ali Bhutto, the father of Benazir. "Everywhere I looked I kept coming up against intelligence about Pakistan's WMD programme," Barlow says. "I thought I was telling them what they needed to hear, but the White House seemed oblivious." Immersed in the minutiae of his investigations, he didn't appreciate the bigger picture: that Pakistan had, within days of Reagan's inauguration in 1981, gone from being an outcast nation that had outraged the west by hanging Bhutto to a major US ally in the proxy war in Afghanistan.

Within months Barlow was out of a job. A small band of Republican hawks, including Paul Wolfowitz, had convinced the president that America needed a new strategy against potential nuclear threats, since long-term policies such as détente and containment were not working. Reagan was urged to remilitarise, launch his Star Wars programme and neutralise ACDA. When the agency's staff was cut by one third, Barlow found himself out of Washington and stacking shelves in a food store in Connecticut, where he married his girlfriend, Cindy. He was not on hand in 1984 when intelligence reached the ACDA and the CIA that Pakistan had joined the nuclear club (the declared nuclear powers were Britain, France, the US, China and Russia) after China detonated a device on Pakistan's behalf.

Soon after, Barlow was re-employed to work as an analyst, specialising in Pakistan, at the Office of Scientific and Weapons Research (OSWR). The CIA was pursuing the Pakistan programme vigorously even though Reagan was turning a blind eye - indeed, Reagan's secretary of state, George Schultz, claimed in 1985: "We have full faith in [Pakistan's] assurance that they will not make the bomb."

Back on a government salary, Barlow, aged 31, moved to Virginia with his wife Cindy, also a CIA agent. From day one, he was given access to the most highly classified material. He learned about the workings of the vast grey global market in dual-use components - the tools and equipment that could be put to use in a nuclear weapons programme but that could also be ascribed to other domestic purposes, making the trade in them hard to spot or regulate. "There was tonnes of it and most of it was ending up in Islamabad," he says. "Pakistan had a vast network of procurers, operating all over the world." A secret nuclear facility near Islamabad, known as the Khan Research Laboratories, was being fitted out with components imported from Europe and America "under the wire". But the CIA obtained photographs. Floor plans. Bomb designs. Sensors picked up evidence of high levels of enriched uranium in the air and in the dust clinging to the lorries plying the road to the laboratories. Barlow was in his element.

However, burrowing through cables and files, he began to realise that the State Department had intelligence it was not sharing - in particular the identities of key Pakistani procurement agents, who were active in the US. Without this information, the US Commerce Department (which approved export licences) and US Customs (which enforced them) were hamstrung.

Barlow came to the conclusion that a small group of senior officials was physically aiding the Pakistan programme. "They were issuing scores of approvals for the Pakistan embassy in Washington to export hi-tech equipment that was critical for their nuclear bomb programme and that the US Commerce Department had refused to license," he says. Dismayed, he approached his boss at the CIA, Richard Kerr, the deputy director for intelligence, who summoned senior State Department officials to a meeting at CIA headquarters in Langley. Barlow recalls: "Kerr tried to do it as nicely as he could. He said he understood the State Department had to keep Pakistan on side - the State Department guaranteed it would stop working against us."

Then a Pakistani nuclear smuggler walked into a trap sprung by the CIA - and the Reagan administration's commitment to rid the world of nuclear weapons was put to the test.

US foreign aid legislation stipulated that if Pakistan was shown to be procuring weapons of mass destruction or was in possession of a nuclear bomb, all assistance would be halted. This, in turn, would have threatened the US-funded war in Afghanistan. So there were conflicting interests at work when Barlow got a call from the Department of Energy. "I was told that a Pakistani businessman had contacted Carpenter Steel, a company in Pennsylvania, asking to buy a specific type of metal normally used only in constructing centrifuges to enrich uranium. His name was Arshad Pervez and his handler, Inam ul-Haq, a retired brigadier from the Pakistan army, had been known to us for many years as a key Pakistan government operative." Barlow and US customs set up a sting. "Pervez arrived to a do a deal at a hotel we had rigged out and was arrested," Barlow says. "But ul-Haq, our main target, never showed."

Trawling through piles of cables, he found evidence that two high-ranking US officials extremely close to the White House had tipped off Islamabad about the CIA operation. Furious, Barlow called his superiors. "The CIA went mad. These were criminal offences," Barlow says. The State Department's lawyers considered their position. They argued that an inquiry would necessitate the spilling of state secrets. The investigation was abandoned just as Reagan made his annual statement to Congress, testifying that "Pakistan does not possess a nuclear explosive device."

But the Pervez case would not go away. Congressman Stephen Solarz, a Democrat from New Jersey, demanded a closed congressional hearing to vet the intelligence concerning Pakistan's bomb programme. Barlow was detailed to "backbench" at the meeting, if necessary offering advice to the White House representative, General David Einsel (who had been chosen by Reagan to head his Star Wars programme). An armed guard stood outside the room where the hearing was held.

Barlow recalls that Solarz got straight to the point: "Were Pervez and ul-Haq agents of the Pakistan government?" Without flinching, Einsel barked back: "It is not cut and dried." It was a criminal offence to lie to Congress, as other hearings happening on the same day down the corridor were spelling out to Colonel Oliver North, the alleged mastermind behind Iran-Contra. Barlow froze. "These congressmen had no idea what was really going on in Pakistan and what had been coming across my desk about its WMD programme," he says. "They did not know that Pakistan already had a bomb and was shopping for more with US help. All of it had been hushed up."

Then Solarz called on Barlow to speak. "I told the truth. I said it was clear Pervez was an agent for Pakistan's nuclear programme. Everyone started shouting. General Einsel screamed, 'Barlow doesn't know what he's talking about.' Solarz asked if there had been any other cases involving the Pakistan government and Einsel said, 'No'." Barlow recalls thinking, " 'Oh no, here we go again.' They asked me and I said, 'Yes, there have been scores of other cases.' "

The meeting broke up. Barlow was bundled into a CIA car that sped for Langley. It was a bad time to be the US's foremost expert on Pakistan's nuclear programme when the administration was desperate to prove it didn't exist. Shortly after, Barlow left the CIA, claiming that Einsel had made his job impossible.

Later that year, Reagan would tell the US Congress: "There is no diminution in the president's commitment to restraining the spread of nuclear weapons in the Indian subcontinent or elsewhere."

Once again, Barlow was able to bounce back. In January 1989, he was recruited by the Office of the Secretary of Defence (OSD) at the Pentagon to become its first intelligence analyst in WMD. For a man uncomfortable with political pragmatism, it was a strange move: he was now in a department that was steeped in realpolitik, balancing the commercial needs of the US military industry against America's international obligations. Within weeks, he had again built a stack of evidence about Pakistan's WMD programme, including intelligence that the Pakistan army was experimenting with a delivery system for its nuclear bomb, using US-provided technology. "Our side was at it again," Barlow says.

Still optimistic, still perhaps naive and still committed to the ideal of thwarting the Pakistan programme, Barlow convinced himself that his experience in the CIA was untypical, the work of a handful of political figures who would now not be able to reach him. When he was commissioned to write an intelligence assessment for Dick Cheney, defence secretary, giving a snapshot of the Pakistan WMD programme, he thought he was making headway. Barlow's report was stark. He concluded that the US had sold 40 F-16 fighter jets to Pakistan in the mid-80s - it had been a precondition of the sale that none of the jets could be adapted to drop a nuclear bomb. He was convinced that all of them had been configured to do just that. He concluded that Pakistan was still shopping for its WMD programme and the chances were extremely high that it would also begin selling this technology to other nations. Unbeknown to Barlow, the Pentagon had just approved the sale of another 60 F-16s to Pakistan in a deal worth $1.4bn, supposedly with the same provison as before.

"Officials at the OSD kept pressurising me to change my conclusions," Barlow says. He refused and soon after noticed files going missing. A secretary tipped him off that a senior official had been intercepting his papers. In July 1989, Barlow was hauled before one of the Pentagon's top military salesmen, who accused him of sabotaging the new F-16 deal. Eight days later, when Congress asked if the jet could be adapted by Pakistan to drop a nuclear bomb, the Defence Department said, "None of the F-16s Pakistan already owns or is about to purchase is configured for nuclear delivery." Barlow was horrified.

On August 4 1989, he was fired. "They told me they had received credible information that I was a security risk." Barlow demanded to know how and why. "They said they could not tell me as the information was classified." All they would say was that "senior Defence Department officials", whose identities were also classified, had supplied "plenty of evidence". The rumour going around the office was that Barlow was a Soviet spy. Barlow went home to Cindy. "We were in marriage counselling following my fall-out at the CIA. We were getting our relationship back on track. And now I had to explain that I was being fired from the Pentagon."

Barlow still would not give up. His almost pathological tenacity was one of the characteristics that made him a great analyst. With no salary and few savings, he found a lawyer who agreed to represent him pro-bono. At this point, more documents surfaced linking several familiar names to Barlow's sacking and its aftermath; these included Cheney's chief of staff, Libby, and two officials working for Wolfowitz. Through his lawyer, Barlow discovered that he was being described as a tax evader, an alcoholic and an adulterer, who had been fired from all previous government jobs. It was alleged that his marriage counselling was a cover for a course of psychiatric care, and he was put under pressure to permit investigators to interview his marriage guidance adviser. "I had to explain to Cindy that her private fears were to be trawled by the OSD. She moved out. My life, professionally and personally, was destroyed. Cindy filed for divorce."

Barlow's lawyers stuck by him, winning a combined inquiry by the three inspector generals acting for the Defence Department, the CIA and the State Department (inspector generals are the equivalent of ombudsmen in Britain). By September 1993, the lead inspector, Sherman Funk, concluded that the accusation of treachery was "an error not supported by a scintilla of evidence. The truth about Barlow's termination is, simply put, that it was unfair and unwarranted." The whole affair, Funk said, was "Kafka-like" - Barlow was sacrificed for "refusing to accede to policies which he knew to be wrong".

It seemed Barlow had been vindicated. However, when the report was published it had been completely rewritten by someone at the Pentagon. Funk was appalled. When Barlow's lawyers called the Pentagon, they were told it was the department that had been exonerated. Now it was official: Pakistan was nuclear-free, and did not have the capability of dropping a bomb from an American-supplied F-16 jet and the reputation of the only man who claimed otherwise was destroyed. Later, Barlow's lawyers would find his brief to Cheney had been rewritten, too, clearing Pakistan and concluding that continued US aid would ensure that the country would desist from its WMD programme.

The Pentagon officials who were responsible for Barlow's downfall would all be out of government by 1993, when Bill Clinton came into the White House. In opposition they began pursuing an aggressive political agenda, canvassing for war in Iraq rather than restraining nuclear-armed Pakistan. Their number now included Congressman Donald Rumsfeld, a former Republican defence secretary, and several others who would go on to take key positions under George Bush, including Richard Armitage, Richard Perle and John Bolton.

Rumsfeld and Wolfowitz headed the Commission to Assess the Ballistic Missile Threat to the United States, which concluded in July 1998 that the chief threat - far greater than the CIA and other intelligence agencies had so far reported - was posed by Iran, Iraq and North Korea: the future Axis of Evil powers. Pakistan was not on the list, even though just two months earlier it had put an end to the dissembling by detonating five nuclear blasts in the deserts of Balochistan.

It was also difficult not to conclude that Islamist terrorism was escalating and that its epicentre was Pakistan. The camps that had once been used to train the US-backed mujahideen had, since the Soviet retreat from Afghanistan, morphed into training facilities for fighters pitted against the west. Many were filled by jihadis and were funded with cash from the Pakistan military.

It was made clear to the new president, Bill Clinton, that US policy on Pakistan had failed. The US had provided Islamabad with a nuclear bomb and had no leverage to stop the country's leaders from using it. When he was contacted by lawyers for Barlow, Clinton was shocked both by the treatment Barlow had received, and the implications for US policy on Pakistan. He signed off $1m in compensation. But Barlow never received it as the deal had to be ratified by Congress and, falling foul of procedural hurdles, it was kicked into the Court of Federal Claims to be reviewed as Clinton left office.

When the George Bush came to power, his administration quashed the case. CIA director George Tenet and Michael Hayden, director of the National Security Agency, asserted "state secrets privilege" over Barlow's entire legal claim. With no evidence to offer, the claim collapsed. Destroyed and penniless, the former CIA golden boy spent his last savings on a second-hand silver Avion trailer, packed up his life and drove off to Bear Canyon campground in Bozeman, Montana, where he still lives today.

Even with Barlow out of the picture, there were still analysts in Washington - and in the Bush administration - who were wary of Pakistan. They warned that al-Qaida had a natural affinity with Pakistan, geographically and religiously, and that its affiliates were seeking nuclear weapons. Some elements of the Pakistan military were sympathetic and in place to help. But those arguing that Pakistan posed the highest risk were isolated. Cheney, Rumsfeld and Wolfowitz were in the ascendant, and they returned to the old agenda, lobbying for a war in Iraq and, in a repeat of 1981 and the Reagan years, signed up Pakistan as the key ally in the war against terror.

Contrary advice was not welcome. And Bush's team set about dismantling the government agency that was giving the most trouble - the State Department's Nonproliferation Bureau. Norm Wulf, who recently retired as deputy assistant secretary of state for non-proliferation, told us: "They met in secret, deciding who to employ, displacing career civil servants with more than 30 years on the job in favour of young, like-thinking people, rightwingers who would toe the administration line." And the administration line was to do away with any evidence that pointed to Pakistan as a threat to global stability, refocusing all attention on Iraq.

The same tactics used to disgrace Barlow and discredit his evidence were used again in 2003, this time against Joseph Wilson, a former US ambassador whom the Bush administration had sent to Africa with a mission to substantiate the story that Saddam Hussein was seeking to buy material to manufacture WMD. When Wilson refused to comply, he found himself the subject of a smear campaign, while his wife, Valerie Plame, was outed as a CIA agent. Libby would subsequently be jailed for leaking Plame's identity (although released on a presidential pardon). Plame and Wilson's careers and marriage would survive. Barlow and his wife, Cindy's, would not - and no one would be held to account. Until now.

When the Republicans lost control of both houses of Congress in 2006, Barlow's indefatigable lawyers sensed an opportunity, lodging a compensation claim on Capitol Hill that is to be heard later this month. This time, with supporters of the Iraq war in retreat and with Pakistan, too, having lost many friends in Washington, Barlow hopes he will receive what he is due. "But this final hearing cannot indict any of those who hounded me, or misshaped the intelligence product," he says. "And it is too late to contain the flow of doomsday technology that Pakistan unleashed on the world."

· Adrian Levy and Catherine Scott-Clark are the authors of Deception: Pakistan, The United States And Global Nuclear Weapons Conspiracy, published later this month by Atlantic Books, £25.

· The following clarification was printed in the Guardian's Corrections and clarifications column, Friday October 19 2007. Lewis "Scooter" Libby was not jailed for leaking the identity of a CIA agent, as we said in this article. He was convicted of perjury and obstructing an investigation into the leak. President Bush did not pardon him, but commuted the sentence to a fine and probation.