The David Ortiz shooting was a case of mistaken identity by a group of bungling hit men who were targeting one of the Red Sox great’s friends — but got confused because they were both wearing white pants, officials reveled on Wednesday.

The roughly $8,000 assassination was ordered against the retired slugger’s pal, David Fernandez, by a drug-cartel member named Victor Hugo Gomez Vasquez, who believed Fernandez had been snitching on him to US authorities, officials in the Dominican Republic said.

The June 9 attack at a Santo Domingo nightclub went haywire when the gunman mixed up the men as they sat together at a table enjoying the evening, according to Attorney General of the Dominican Republic Jean Alain Rodriguez.

One of the men involved in the plot had been hiding inside the Dial Bar and Lounge before the attack and snapped a photo of Fernandez, which he then circulated to the contract killers, officials said.

It showed their intended target in white pants partying with “Big Papi” and some other pals. Unfortunately, the 43-year-old Boston sports hero also was wearing white that night. A video of the attack showed the gunman approaching Ortiz from behind in an outdoor area of the hot spot and firing into his lower back at point-blank range before escaping on a motorcycle.

The bullet went through Ortiz’s abdomen and entered the leg of his other friend, TV host Jhoel Lopez. Fernandez was unharmed.

The man who authorities believe was planning to pay for the killing, Alberto Miguel Rodriguez Mota, was sitting just feet away from the attack at the night club’s bar and watched the entire murder attempt go down. He allegedly had the job of confirming Fernandez had been snuffed out — and when he saw it was Ortiz who was shot instead, he refused to pay the incompetent gunmen their cash.

The attack left Ortiz in intensive care, but he is in good condition and expected to fully recover.

Vasquez is believed to have ordered the hit from somewhere in the United States, where he is believed to still be on the run, officials said.

“The last time we located Victor Hugo Gomez was in the United Statesm and we believe that from there he planned the whole operation to attack the life of David Fernandez,” Rodriguez said of the assassination attempt.

“I will not rest until all the people involved are arrested.”

Police have so far arrested 11 suspects, including gunman Rolfi Ferreira Cruz, who tried and failed to escape from the crime scene on a motorcycle. He had earlier told reporters from prison that he didn’t mean to shoot Ortiz.

The claim was initially dismissed as far-fetched by prosecutors, who found it hard to believe any Dominican would not recognize the country’s most famous athlete.

“It wasn’t David, it wasn’t for David . . . was confused,” Ferreira Cruz shouted to journalists in Spanish through the bars of a police holding cell, according to local outlet El Caribe.

Ferreira Cruz, 25, claimed he was thrown off by the colors of Ortiz’s duds, local newspaper Listin Diario reported.

Rodgriguez said Vasquez — who served time in the Dominican Republic in 2011 for trafficking cocaine — reached out to his old prison buddies to arrange the hit. He called on Vasquez, Mota and another alleged plotter who is still at large, Luis Alfredo Rivas Clase, to turn themselves in.

“These three individuals, turns yourselves in because we are looking for you. I repeat that we are collaborating with agencies from the United States.”

Fernandez has denied that he was target, telling a Dominican radio program he had no enemies, did not have any money and was an ordinary citizen, Listin Diario reported.

Fernandez also claimed he ran an automotive workshop.

Ortiz’s lawyer on Wednesday sought to defend his reputation, claiming he was an upstanding family man with no criminal connections.

“He has no connection to illicit activities, no relationships with people who have criminal connections, nor has he violated his family values that would bring about such an incident,” lawyer Jose Martinez Hoepelman told The Boston Globe earlier in the day.

Hoepelman said unsubstantiated online reports about Ortiz being involved in a relationship with a drug lord’s girlfriend were “not based in fact” and instead created “confusion” during the police investigation.

Ortiz is a man of “family values and no enemies,” his lawyer added.

As Ortiz continues to recover in intensive care at Massachusetts General Hospital in Boston, his wife, Tiffany, revealed doctors had upgraded Ortiz’s condition to good.

She thanked the public for their support during what she described as a “challenging time.”

Rodriguez said that the findings that Ortiz was an innocent bystander should quash speculation that he was involved in anything nefarious that prompted the attack.

“It’s shameful that there’s been all these assumptions about a person of the caliber of David Ortiz,” he added.