President Donald Trump seems to believe that FBI agents infiltrated his presidential campaign for political purposes, and has tweeted that the bureau’s actions could amount to a scandal “bigger than Watergate.”

Trump hasn’t provided evidence to support these allegations, but regardless of their veracity, there is precedent for an American intelligence agency spying on a presidential campaign. It happened in the summer of 1964; the target was Republican presidential candidate Barry Goldwater, and the perpetrator was the CIA, not the FBI.

A CIA officer named E. Howard Hunt — later made infamous for his role in the Watergate break-in — was in charge of the operation. Hunt’s role in the Goldwater caper can be traced back to his involvement in the CIA’s disastrous attempt to depose Fidel Castro by landing a ragtag group of Cuban exiles at the Bay of Pigs in April 1961. Like many agency officers associated with the fiasco, he was put in a kind of purgatory, assigned to a desk job that lacked the excitement or career-advancement potential of foreign clandestine operations.

In Hunt’s case, the CIA tasked him with oversight of clandestine operations with cryptonyms like WUBONBON and WHUHUSTLER that produced and disseminated propaganda for consumption in the United States and internationally. One such propaganda project was a CIA front company called Continental Press, which operated as a news service based out of an office in the National Press Building in downtown Washington. Run by a former Associated Press reporter, Continental Press fed news and propaganda to obscure newspapers in developing countries, and provided cover for CIA operatives in Africa, India and elsewhere.

Over a six-week period in the late summer of 1964, Hunt deployed Continental Press staff to undertake a new type of project: infiltrating the presidential campaign of Barry Goldwater on behalf of President Lyndon Johnson.

Even in the heat of the ’64 campaign, as he thought he was being spied on, Goldwater never mentioned his concerns publicly, and even insisted that his aides kept quiet

There is some dispute about whose idea this was. In a memoir published in 2007, Hunt claimed the idea to spy on Goldwater originated in the White House. Johnson, had, Hunt claimed, “become obsessed with obtaining his competitor’s plans.” Having come to office through tragedy, and deeply resenting suggestions that he wasn’t up to the job, Johnson yearned for a blow-out victory in 1964’s presidential race.

In 1975, then CIA Director William Colby told the House Select Committee on Intelligence that spying on Goldwater had been the brainchild of Tracy Barnes, head of the CIA’s Domestic Operations Division. According to Colby’s version of events, Barnes proposed it to Chester L. Cooper, a CIA officer working in the Johnson White House on temporary assignment to the National Security Council.

According to a CIA memo Colby provided to Congress, in 1973 Cooper told a member of the CIA Office of Inspector General that in 1964 Barnes had asked him “if he would like to have copies of [Goldwater’s] speeches and would it be useful to have them before he (Cooper) read them in the newspapers.” The memo concluded: “There is no question that Mr. Cooper was serving the White House in the political campaign while on the CIA payroll and that he was assisted, in part, by a member of the Agency’s Domestic Operations Division.” The CIA didn’t say why Barnes offered to spy on Goldwater. He may have been seeking to enhance the agency’s stature at a time when President Johnson had a strained relationship with its director.

In blaming Barnes and saying that he hadn’t informed anyone more senior about the operation, Colby created a convenient dead-end: by the time the Agency pinned responsibility on Barnes, he had been dead for several years.

Whether the impetus came from the White House or Langley, it is clear that Hunt arranged the infiltration of the Goldwater campaign headquarters. “My subordinates volunteered inside, collected advance copies of position papers and other material, and handed them over to CIA personnel,” Hunt wrote. Hunt’s assets included a secretary on Goldwater’s campaign staff who provided advance copies of speeches and press releases. A female CIA employee who worked from the Continental Press offices would pick up the material and deliver it to Cooper.

LBJ wasn’t squeamish about using the inside information, and he did so in a blunt fashion that must have made CIA officers cringe. Goldwater campaign staff noticed that the Johnson campaign had the unnerving habit of responding to points in their candidate’s speeches before he had delivered them. Johnson didn’t seem to care that his actions made clear to Goldwater that he was being spied on.

One of the most glaring incidents took place on September 9, 1964, after Hunt’s operation delivered to Cooper an advance copy of a speech Goldwater was slated to deliver that evening in Seattle. The Republican planned to announce formation of a Task Force on Peace and Freedom headed by former Vice President Richard Nixon that would advise Goldwater on foreign affairs. The idea was to calm fears that Goldwater had insufficient foreign-policy experience and that he would pursue a radical international agenda.

Johnson swung into action and called a “flash” press conference. While Goldwater was on an airplane and unable to respond, LBJ announced the formation of a task force of his own: a “panel of distinguished citizens who will consult with the president in the coming months on major international problems facing the United States.” Johnson’s ploy worked perfectly: news of his advisory panel was widely reported, including on the front page of the New York Times, while Goldwater’s announcement received little attention.

The disparity caught the attention of the journalist Arthur Krock, who in a nationally syndicated column suggested that Goldwater had “forfeited a chance to name his ‘task force’ first, and then represent the President’s as another instance of ‘me too.’”

Krock presented the situation as a triumph for Johnson and an example of the natural advantages a sitting President had in an election campaign. “Among advantages a president in a campaign to succeed himself has over his opponent is command of the channels of publicity,” he told his readers. Goldwater was hopelessly outmatched when going up against the full weight of the presidency, Krock wrote: “The President of the United States in the classic décor of his oval office at the White House; his helplessly scooped opponent in the modernistic carnival setting of the Coliseum that was built for the Seattle World’s Fair.”

The CIA’s surveillance of Goldwater didn’t alter the outcome of the election — Johnson was up big, and won in a landslide. But, at least in Hunt’s mind, it eventually led to the downfall of a president — just not the president involved.

Hunt retired from the CIA in 1970 and was hired by the White House in 1972 to lead a unit known as the Plumbers that was dedicated to plugging leaks within the Nixon administration, playing dirty tricks on Nixon’s opponents and obtaining political intelligence. Years later, Hunt justified his actions by comparing them to the CIA’s spying on Goldwater. His logic was that if it was OK to use surreptitious methods to obtain political intelligence on behalf of one president, it was acceptable to do the same for another president. “Since I’d done it once before for the CIA, why wouldn’t I do it again [inside Watergate in June 1972] for the White House?” Hunt explained to the New York Times in late December 1974.

In 1973, Judge John J. Sirica imposed a provisional 35-year prison sentence on Hunt for his role in planning the Watergate break-in, and said he would reduce the term only if Hunt cooperated with government investigators. Traumatized by prison, grieving the death of his wife in a December 1972 plane crash, and feeling the government had betrayed him, Hunt decided to talk. On December 18, 1973, on a closely guarded excursion from a federal penitentiary in Allenwood, Pennsylvania, Hunt met with Senator Howard Baker, Jr. and the staff of a Senate committee that was investigating CIA abuses of power.

Hunt told Baker that he’d been disturbed by the order to spy on the Goldwater campaign. This wasn’t because he had any hesitation about conducting what was obviously an illegal violation of the CIA’s charter, which imposes strict limits on the agency’s domestic operations.Rather, it was because Hunt was one of the few Goldwater supporters in the agency. “However, as distasteful as I thought it was, I performed the duty, accepting White House orders without question,” he recalled. A year later, news of Hunt’s testimony leaked to the New York Times.

In testimony before the House Intelligence Committee in 1975, CIA Director William Colby indicated that he also found Hunt’s activities distasteful. “I certainly would not countenance picking up speeches by another candidate and giving them to the White House,” Colby said.

After Hunt’s revelations were leaked to the press, Sen. Goldwater told Washington Post reporters that during the 1964 campaign, he had come to believe he was being spied on. “I just assumed it was one man or two men assigned at the direction of the President … It never bothered me,” he said. “I guess it should have, but knowing Johnson as I did, I never got upset about it.” Goldwater never suggested that the CIA’s spying had cost him the election.

Even in the heat of the ’64 campaign, as he thought he was being spied on, Goldwater never mentioned his concerns publicly, and even insisted that his aides kept quiet. Going public with the allegations would have distracted attention from his agenda, and absent any proof that surveillance was actually happening, complaints about being spied upon would’ve likely reinforced the common perception that he was paranoid.

It’s a very different course of action than the one President Trump is taking today.

Steve Usdin is the author of the forthcoming Bureau of Spies: The Secret Connections between Espionage and Journalism in Washington, from which this piece was adapted.