Former baseball players Octavio Dotel and Luis Castillo walked free from a jail in the Dominican Republic on Thursday after a judge suddenly ruled there wasn’t enough evidence to link them to drug kingpin Cesar Emilio Peralta, according to various news reports in the Caribbean nation.

Dotel, a pitcher, and Castillo, an infielder, were charged last week with being members of Peralta’s cocaine and opioid empire in what Dominican Republic Attorney General Jean Alain Rodriguez said was the nation’s largest operation targeting an organized-crime ring.

The former Mets were said to be among 18 members of a massive drug operation overseen by Peralta — whose nickname is “Cesar the Abuser.”

Prosecutors claimed Peralta leaned on the big-name pals to help launder his ill-gotten gains.

But on Thursday, Judge José Alejandro Vargas declared that the drug-trafficking charges against the former major-leaguers were without merit.

“The authorities owe a public explanation to Octavio Dotel,” the former ace pitcher’s lawyer, Manuel Sierra, told ESPN Deportes.

“The judge found that my client has nothing to do with the charges imputed to him by the public prosecutor.

Dotel, however, was still facing a weapons charge from when ­authorities discovered an illegal firearm while searching his home.

“About the firearm that was seized in one of his vehicles, we have the documentation that proves that it is not illegal and we will present it in the court in a timely manner,” Sierra said.

Dotel posted $1 million bail. It was not clear when or if he needed to return to court.

Castillo’s attorney, Darren Heitner, could not be reached for comment late Thursday.

Last week, the attorney insisted his client was innocent and demanded an apology.

“Luis Castillo has not been involved in any drug trafficking whatsoever,” he told the Web site The Athletic at the time.