Federal prosecutors said Wednesday they will not retry Sen. Robert Menendez, D-N.J., on corruption charges, acknowledging that recent court rulings left them with a weakened case.

Prosecutors also sought in the same filing in New Jersey federal court to dismiss the remaining charges against Dr. Salomon Melgen, the Florida eye doctor accused of bribing Menendez with pricey trips and donations in order to obain political favors.

The decision to drop the case came almost exactly five years to the day that FBI agents raided Melgen's office as part of the probe of his relationship with Menendez.

The move also came more than two months after Menendez's first trial on those charges ended in a mistrial when jurors deadlocked on a verdict — and just two weeks after prosecutors said they planned to retry him. Their motion filed Wednesday asks a judge to dismiss the indictment pending against both Menendez and Melgen.

Menendez, in a prepared statement, said, "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. I thank God for hearing my prayers and for giving me strength during this difficult time," the senator said.

"I have devoted my life to serving the people of New Jersey, and am forever thankful for all who have stood by me. No matter the challenges ahead, I will never stop fighting for New Jersey and the values we share."

Menendez is a heavy favorite to win re-election in November to a third term in the Senate, where Republicans hold a slim, 51-49 majority.

The Justice Department, in a statement explaining its decision to drop the case, cited an order last week by trial Judge William Walls, who declared Menendez not guilty of seven counts in the indictment lodged against the 64-year-old senator. The judge said a 2016 Supreme Court ruling had undercut a large part of the prosecutors' theory in the case.

The judge's ruling left 11 counts pending against Melgen and Menendez.

Justice officials also Wednesday cited limitations placed by the judge on the evidence that would be admissible at a retrial.

"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," said a Justice Department spokeswoman.

In their own court filing Wednesday, lawyers for Menendez and Melgen said they did not object to the prosecutors' motion to dismiss the indictment.

But defense lawyers asked the judge to dismiss all of the remaining charges "with prejudice," which would bar prosecutors from ever attempting to bring Menendez and Melgen to trial for the same conduct that was the subject of this case. The judge has yet to rule on the motion to dismiss filed by prosecutors, but his approval is all but guaranteed.

Abbe Lowell, Menendez's lawyer, said in a statement, "In light of the results of a three month trial, all the jury said and the granting of our motion for acquittal on significant counts, we are pleased and grateful that the Justice Department made the right decision to end this case."

"Despite the five years of this ordeal, Senator Menendez never wavered in his innocence and his commitment to the people of New Jersey. We were fortunate to be able to assist this honorable man," Lowell said.

Menendez was accused of accepting favors from Melgen, which allegedly included a dozen flights on the doctor's private jet to a resort in the Dominican Republic, a three-night stay in a pricey Paris Hotel, and more than $700,000 in political contributions to both the senator and the Democratic Party.

Prosecutors claimed that Melgen, in return for his largesse, got help from Menendez in obtaining visas for girlfriends of the doctor.

Menendez also helped a Melgen-owned firm get a contract worth millions of dollars for port security in the Dominican Republic, and also pressured federal regulators in connection with their inquiry into alleged Medicare overbilling by Melgen, prosecutors said.

Kirk Ogrosky, Melgen's lawyer, in an emailed statement, said, "Five years ago ... FBI agents started this misguided case and destroyed our client's life when they raided his West Palm Beach medical office."

"Dr. Melgen is now, and has always been, innocent of the charges brought in New Jersey," Ogrosky said. "He has never given anything to U.S. Senator Robert Menendez, his best friend of over 20 years, with any expectation of getting anything in return. We are also grateful for the Court's defense of the First Amendment when issuing its recent order of acquittals."

"We take no pleasure in seeing justice done so late in a case that should never have been filed. But justice today is certainly better than justice delayed if the prosecution had pushed the remaining counts forward, into what would have been an inevitable acquittal. We hope that the Department of Justice lives up to its name and never brings this type of meritless case again."