Charges in Massachusetts were dropped Wednesday against actor Kevin Spacey, who had been accused of groping the son of a former Boston television news anchor at a Nantucket bar three years ago.

Cape & Islands District Attorney Michael O'Keefe cited the "unavailability of the complaining witness" in filing for dismissal in the Nantucket District Court.

And Judge Thomas Barnett accepted the prosecution request, and formally threw out the case, according to court documents filed late Wednesday.

The case against Spacey appeared to suffer a fatal blow last week when his accuser invoked his Fifth Amendment rights after being questioned about his role in the deleting of text messages from a phone key to the case.

Spacey's defense had demanded to examine the accuser's cellphone that he had in the early morning hours of July 8, 2016, when the alleged incident happened at the Club Car restaurant and bar in Nantucket.

On the witness stand, the accuser said he had not altered or deleted any potential evidence off that iPhone he had in 2016.

But when Spacey's lawyer, Alan Jackson, reminded him it is a felony to alter evidence, the court took a break and then the young man told Judge Barrett — through a public defender assigned on the spot — he'd invoke his right against self-incrimination on the phone issue.

The young man and his family met with prosecutors Sunday and he decided not to waive his right to invoke the Fifth.

"The complaining witness was informed that if he chose to continue to invoke his Fifth Amendment right, the case would not be able to go forward," according to a statement issued by the prosecutors.

"After a further period of reflection privately with his lawyer, the complaining witness elected not to waive his right under the Fifth Amendment."

The accuser's attorney, Mitchell Garabedian, said Wednesday, "My client and his family have shown an enormous amount of courage under difficult circumstances."

In theory, prosecutors could have granted the accuser immunity for his testimony — but that would make a conviction virtually impossible with such a tainted witness.

"A grant of immunity compromises the witness to a degree which, in a case where the credibility of the witness is paramount, makes the further prosecution untenable," according to prosecutors.

In court last week, Jackson said the case against his client was dead.

"This entire case is completely compromised. He is the sole witness," he said. "This case needs to be dismissed, and I believe it needs to be dismissed today."