The Justice Department filed a motion to dismiss its indictment against Sen. Bob Menendez (D-NJ) Wednesday — a move that signals the end of a years-long effort to prosecute the senator on corruption charges.

Last November, Menendez’s trial ended with its judge declaring a mistrial, because the jury failed to reach unanimous agreement on any of the charges Menendez faced.

The mistrial left open the possibility that the government could prosecute Menendez again, on the same charges, and the Justice Department originally said it intended to do so. But last week, the judge, William Walls, dismissed four of the counts Menendez had been charged with, saying no “rational juror” could be persuaded of them.

That appears to have been the impetus for the Justice Department to throw in the towel, ending a prosecution that began all the way back in April 2015.

This result doesn’t necessarily take Menendez out of the woods politically. He’s up for reelection this November and his approval ratings are quite low, making him potentially vulnerable. But the New Jersey Democratic Party is formidable and hierarchical in primaries, and the national environment doesn’t appear to bode well for a Republican challenger. So, should he run again, he’d start off as the favorite to win a full third term.

What the trial was about

Menendez, the son of Cuban immigrants, rose to political prominence in Hudson County, New Jersey, in the 1980s, before winning a seat in the House of Representatives in 1992 and then an appointment to a US Senate vacancy in 2006. He’s a former chair of the Democratic Senatorial Campaign Committee and of the Senate Foreign Relations Committee. His politics are standard-issue liberal on most matters, though he’s notably more hawkish than most Democrats on foreign policy topics such as Cuba and Iran.

But Menendez fell under Justice Department scrutiny for his relationship with a wealthy Florida eye doctor, Salomon Melgen, whom he often traveled with. In April 2015, prosecutors filed corruption charges against Menendez (and against Melgen), arguing that Menendez used his position to benefit Melgen in return for items of value.

Prosecutors alleged that Melgen gave Menendez:

Many flights on his company’s private jets, and at least one first-class commercial flight (Menendez didn’t initially disclose these in Senate ethics filings, and paid Melgen back for some of the flights years later)

Use of a Caribbean villa, access to a Dominican resort, and a stay at a luxury Paris hotel

Tens of thousands of dollars for his legal defense fund

Hundreds of thousands of dollars earmarked to be spent to help his 2012 reelection effort

In return, they alleged, Menendez did several things for Melgen:

He met with then-Health and Human Services Secretary Kathleen Sebelius over a billing dispute Melgen was having with Medicare, and advocated on Melgen’s behalf. (In a separate trial, Melgen was convicted earlier this year of defrauding Medicare of more than $90 million from charges stemming from this dispute.)

He tried to get the State Department to push the Dominican Republic to uphold a contract Melgen had to provide cargo screening in the country’s ports.

He tried to stop US Customs and Border Protection from donating cargo screening equipment to the Dominican Republic, because of that same port contract Melgen had.

He had his staffers help get tourist or student visas for three of Melgen’s foreign girlfriends.

Menendez has maintained his innocence, and said that while Melgen was a close friend, he did nothing illegal on the doctor’s behalf.

Why prosecutors had a difficult time proving their case

In attempting to prove public corruption charges against a politician, prosecutors have to make the case that the defendant knowingly abused his power as part of a corrupt quid pro quo.

That is: These prosecutors had to prove that Menendez did or promised to do “official acts” that Melgen wanted, and that these acts were done in return for the various gifts and other benefits that Melgen sent his way.

But there’s a moderately high bar for just what counts as an “official act.” In a ruling last year, the Supreme Court overturned former Virginia Gov. Bob McDonnell’s corruption convictions, because they related mainly to meetings he had set up and events he had hosted on behalf of a donor.

"Setting up a meeting, talking to another official, or organizing an event — without more — does not fit that definition of ‘official act,’" the justices wrote. Instead, they said, such an act must involve “a formal exercise of government power.” An actual policy change would count, and the justices also said that exerting “pressure” on another official to change policy or even simply promising to change policy would also count.

Prosecutors argued that Menendez tried to pressure HHS, State, and Customs officials on Melgen’s behalf in specific meetings and interactions. However, they presented no evidence that Menendez did those things for Melgen specifically in return for hotel stays, flights, and donations.

Judge Walls cited that problem last week, when he threw out 7 of the 18 charges against the pair (four of which were about Menendez). “A rational juror could not find that Menendez and Melgen were aware of the terms of the alleged quid quo,” he said. And though Walls didn’t throw out the rest of the charges, this appears to have driven the Justice Department to call it quits on this prosecution.

What comes next for Menendez

Menendez has said he intends to run for reelection this year, though he hasn’t yet officially announced it.

New Jersey is a blue state, and President Trump’s national unpopularity would seem to advantage the Democratic nominee in New Jersey next year. Still, a corruption scandal — even if it didn’t end in a guilty plea — is the sort of thing that could make a safe seat a bit more competitive, should the GOP find a strong challenger. (They haven’t yet.) And indeed, a Quinnipiac poll last fall found that only 20 percent of New Jersey voters thought Menendez should be reelected, compared to 50 percent who say he shouldn’t.

One would think all this would Menendez vulnerable to a primary challenge. But that’s particularly difficult in New Jersey, which has a strong and hierarchical Democratic Party. (The state has a rule in which county party’s endorsed candidates are specially marked on the ballot during primaries, in what’s known as the “county line” — a procedure that likely gives incumbents even more of an advantage than in typical primaries.)

Still, one Democrat — Michael Starr Hopkins, an attorney who’s worked on the Obama and Hillary Clinton presidential campaigns — announced this week that he’d challenge Menendez. “How can we run against the corruption of Donald Trump if we’re excusing corruption within our own party?” he asked, according to NJ.com. The primary will take place in June.