In a shocking turnaround, the U.S. Justice Department has dropped its case against U.S. Sen. Robert Menendez.

In a court in Newark on Wednesday, federal prosecutors moved to dismiss the corruption indictment against the New Jersey Democrat after a federal judge last week acquitted Menendez and his co-defendant, Salomon Melgen, of seven of the 18 counts against them.

Both were facing a retrial after a deadlocked jury could not reach a verdict in the high-profile case in November.

"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 Department of Justice spokeswoman Nicole Navas Oxman.

Hours later, Chief Judge Jose Linares signed an order of dismissal.

In a statement, Menendez said he never wavered in his innocence and his 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," he said. "I thank God for hearing my prayers and for giving me strength during this difficult time. 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."

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. — Senator Bob Menendez (@SenatorMenendez) January 31, 2018

Defense attorney Kirk Ogrosky, who represents Melgen, said the case began five years ago when "FBI agents started this ill-fated adventure that destroyed my client's life," when they raided his office in West Palm Beach.

Melgen was later convicted on separate Medicare fraud charges.

"Dr. Melgen is now and has always been innocent of the charges brought in New Jersey," said Ogrosky. "He did not ever give anything to his best friend of over 20 years with an expectation that he would get something in return. We take no pleasure in seeing justice done at this stage in a case that should never have been brought."

The decision to dismiss the charges will have significant political consequences for Menendez, who is seeking re-election to the Senate this year and faced the possibility of a retrial on the eve of that campaign.

It also marks a surprising turnaround for the Justice Department, which had announced that prosecutors would pursue a retrial.

Menendez and Melgen were charged in April 2015, in a case brought out of Washington by the Justice Department's anti-corruption unit. The government had argued that Menendez, 64, traded the power of his office in exchange for six-figure campaign contributions, luxury hotel stays and private jet flights.

They claimed that Melgen, an ophthalmologist and long-time friend of Menendez, had sought the senator's intervention on the doctor's behalf in an $8.9 million Medicare billing dispute, as well as visa applications of Melgen's foreign girlfriends and a contested port security contract in the Dominican Republic that would benefit one of Melgen's companies.

Menendez was also accused of making false statements on Senate disclosure forms by intentionally concealing Melgen's gifts.

He still faces a Senate ethics probe on failing to list those gifts on his disclosure forms.

The defense argued that the gifts came out of 20 years of friendship and that Menendez's staff mistakenly believed they were exempt from disclosure requirements.The senator's lawyers also argued that Melgen's campaign contributions followed years of financial support for political campaigns outside his home state of Florida.

But after a seven-week trial, jurors in Newark said they could not reach a verdict and told reporters they had been deadlocked 10-2 for acquittal.

Just over a week ago, prosecutors said they intended to seek a retrial.

"The conduct alleged in the indictment is serious and warrants retrial before a jury of citizens in the District of New Jersey," said a spokesman following that filing. "The decision to retry this case was made based on the facts and the law, following a careful review."

Last week, however, U.S. District Judge William Walls unexpectedly acquitted Menendez and Melgen on seven major charges against the two men, in connection with political contributions involving hundreds of thousands of dollars by Melgen that went to several political committees with ties to the senator. He said, "There is no there there."

Walls, in his opinion, said the government "failed to produce evidence of facts either direct or circumstantial" to prove a quid pro quo and that from the evidence, a rational juror could not find that Menendez and Melgen were aware of the terms of the alleged quid quo.

Joseph Hayden of Pashman Stein Walder Hayden, a prominent New Jersey defense attorney, was not surprised by the decision of the Justice Department to seek dismissal.

"Given the overwhelming number of the jurors in favor of acquittal, and the decision by Judge Walls entering a judgment of acquittal for insufficient evidence to prove the political contribution counts, it was clear the government had no choice but to dismiss the counts," Hayden said. "They did not have a provable case."

Robert Mintz, a former federal prosecutor and now a criminal defense attorney at McCarter & English, said the decision by Walls had knocked out a major part of the government's case. At the same time, he said it was a political corruption case built entirely on circumstantial evidence.

"With no cooperating witness, no tape recordings and no videotapes, this was always going to be a challenging case for the government," observed Mintz. "The judge's decision to dismiss the bribery charges involving political contributions left prosecutors with an even more difficult case and less evidence with which to prove it."

Ted Sherman may be reached at tsherman@njadvancemedia.com. Follow him on Twitter @TedShermanSL. Facebook: @TedSherman.reporter. Find NJ.com on Facebook.