A federal judge dismissed all charges against Sen. Robert Menendez (D-N.J.) Wednesday, following a request from prosecutors — a legal surrender in a high-profile test of the Justice Department's enforcement of public integrity laws.

Prosecutors filed a short motion asking U.S. District Court Judge Jose Linares to "dismiss the superseding indictment'' against Menendez, and the request was granted hours later.

In response to the Justice Department's decision to drop the charges, Menendez said in a statement, "From the very beginning, I never wavered in my innocence and my belief that justice would prevail. I am grateful that the Department of Justice has taken the time to reevaluate its case and come to the appropriate conclusion."

The move to dismiss charges is a complete reversal from the position taken by prosecutors just two weeks earlier, when they filed notice to the court they intended to keep pursuing the case after the first trial ended in a hung jury.

Days after that filing, however, U.S. District Court Judge William Walls, who had presided over the first 2½-month trial in Newark, subsequently dismissed seven of the 18 counts in the indictment, but let stand the 11 remaining charges.

"Given the impact of the court's Jan. 24 order on the charges and the evidence admissible in a retrial, the United States has determined that it will not retry the defendants on the remaining charges,'' the Justice Department said in a statement.

Salomon Melgen, a Menendez political donor, was also on trial. Prosecutors said Menendez took gifts from Melgen, a Florida eye doctor, including a luxury hotel stay, private jet flights and campaign donations, in exchange for which he tried to help Melgen get U.S. visas for his girlfriends, intervened in the eye doctor's $8.9 million billing dispute with Medicare, and assisted with a port security contract of Melgen's in the Dominican Republic.

"This case has been on a long, winding road, and this is a surprising end,'' said Robert Mintz, a New Jersey lawyer and former federal prosecutor. "It's certainly a major setback for the Department of Justice, given the high-profile nature of this case.''

Mintz noted that a recent Supreme Court decision had curtailed the reach of some corruption laws, requiring prosecutors to show a direct quid pro quo between gifts accepted by a public official and official acts. Mintz said a key weakness in the Menendez prosecution case was the lack of direct evidence, like a wiretap or a cooperator, to show the intent of the defendants.

"The legal standard has tightened up," he said, "and this case stands for the proposition that unless prosecutors have an insider to the scheme to provide jurors an insight to the intent, it's going to be very difficult."

The first trial of Menendez and Melgen ended in a mistrial in November, with 10 of the 12 jurors voting to acquit him, according to a member of the jury.

Melgen was convicted earlier in a separate case in Florida about the Medicare billing, and is awaiting sentencing.

Melgen's lawyer Kirk Ogrosky said the doctor "is now and has always been innocent of the charges brought in New Jersey. He did not ever give anything to his best friend of over 20 years with an expectation that he would get something in return."

Menendez has long maintained that the government's charges are an attempt to criminalize a longtime friendship between the two men, and that there was nothing corrupt about his acts on Melgen's behalf or Melgen's financial support of the senator.

Judge Walls had dismissed the charges involving Menendez's efforts on Melgen's behalf in the Medicare billing dispute and the port security contract, saying prosecutors wanted the court "to fashion speculative inferences under the conclusory generalizations of context, chronology, escalation, concealment, and a pattern of corrupt activity — each of which is empty of relevant evidential fact." He then quoted writer Gertrude Stein's famous line, "There is no there there.''

In a December interview with reporters, Menendez sharply criticized the FBI and Justice Department for how they had pursued him, suggesting his Hispanic heritage — and his roots in New Jersey's Hudson County, an area with a history of political corruption — may have played a role.

"We have nearly 10 different individuals who had nothing to do with the case, who were gone to and were asked, 'What can you give us on Menendez?' " the senator said. "Forget about me — the Department of Justice is not supposed to be doing that, and its agents are not supposed to be doing that. The only thing I can possibly think of is that you can't believe that a Latino kid who grew up poor and ultimately comes from this county that has a history — somehow, how does he get to be a U.S. senator without doing things that are wrong?"

The Menendez trial was also a test of anti-bribery laws in the wake of a 2016 decision by the Supreme Court narrowing their scope.

In that decision, the high court unanimously overturned the public corruption conviction of former Virginia Gov. Robert F. McDonnell (R), ruling that prosecutors had to meet a higher threshold of evidence.

Chief Justice John G. Roberts Jr. described McDonnell's actions as "tawdry" but agreed that instructions to the jury in his case about what constitutes "official acts" were so broad, they could cover almost any action a public official takes.

"Our concern is not with tawdry tales of Ferraris, Rolexes, and ball gowns," Roberts wrote. "It is instead with the broader legal implications of the Government's boundless interpretation of the federal bribery statute."