FBI agents and federal prosecutors got into a bitter feud over whether to pursue a pay-to-play probe into the Clinton Foundation — and the fight went public Thursday when some of the combatants went rogue and leaked the dispute to the media.

The New York agents were determined to proceed after hearing secret recordings of an unidentified suspect in a public corruption probe talking about cash flowing into the foundation from foreign donors seeking favors from the State Department, The Wall Street Journal reported.

The field agents also spoke to informants and thought they had enough evidence to go after the family’s foundation — and possibly Hillary Clinton herself — but some of the bureau’s brass and prosecutors at the Justice Department dismissed the recordings as hearsay, sources involved with the case told the Journal.

The recordings came up during the bureau’s investigation of the foundation — which began in the summer of 2015 — following the publication of “Clinton Cash: The Untold Story of How and Why Foreign Governments and Businesses Helped Make Bill and Hillary Rich,” by conservative author Peter Schweizer.

The disagreement turned serious in February — just as the Democratic primaries and caucuses were beginning — and remains unresolved, with agents contending they were ordered to “stand down” by lawyers in the Obama administration’s Justice Department.

But Fox News reported Thursday that the FBI probe remains ongoing, despite Justice’s alleged efforts to shut it down.

Justice officials insist the agents were overreaching — and that what has become an extraordinary public battle was just another example of the usual tensions between agents and their supervisors and the FBI and Justice prosecutors.

The case focused on whether Hillary Clinton or her staff gave special treatment to donors during her time as secretary of state.

The Journal said that Robert Capers, who replaced Loretta Lynch as Brooklyn US attorney when Lunch became attorney general, fanned the flames by telling the investigators and Justice and FBI brass what they wanted to hear.

One explanation for which side people came down on was how credible they thought the book was.

Clintonistas had dismissed it as a hatchet job packed with lies and innuendo, and defended the foundation as a model charity.

Others believed it showed a clear pattern of quid pro quo involving donors hungry for favors, the Clintons’ insatiable greed and Hillary’s willingness to bend the rules for fat cat foreigners.

In February, FBI officials, public-integrity prosecutors and Leslie Caldwell, the head of the criminal division at Justice, met in Washington, while prosecutors from Capers’ office did not attend.

Caldwell and her staffers were unimpressed by the evidence.

“The message [to the FBI] was, ‘We’re done here,’ ” sources told the paper. After that meeting, Justice brass sent the “stand down” message.

In later conversations with Justice officials, Capers said the FBI agents on the case “won’t let it go,” the sources said.

As a result, a senior Justice Department official called the FBI deputy director, Andrew McCabe, on Aug. 12 to complain that the New York agents were disregarding their orders, the sources said.

“Are you telling me that I need to shut down a validly predicated investigation?’’ McCabe demanded.

The official replied, ”Of course not.”

Capers’ office declined to comment.

Last week, FBI Director James Comey notified Congress that new evidence had emerged in the Hillary Clinton e-mail investigation, jolting the presidential campaign just days before Election Day.

Additional reporting by Daniel Halper