The chain of events that led to the shooting death of Patrick Dorismond began when one undercover cop diverted from a plan that had been set in place before the officers hit the street.

Cops setting off on a buy-and-bust operation have a pre-determined list of locations — known as “sets” — they will hit in a particular order.

As the three cops headed to their car to drive to from one “set” to another, one of them noticed Dorismond and his friend outside a bar called Wakamba and decided they looked suspicious. He told his partners he wanted to see if the two men would sell him drugs.

Departing from the original plan is not unheard of, a source said, and is not improper, providing the other cops on the team are notified, as was the case.

It was also learned that a cop involved in the shooting may have taken at least one action that, while not against the rules, does fall into a gray area.

Some witnesses told investigators the fatal shot went off when Detective Anthony Vasquez, one of three cops involved in the incident, struck Dorismond in the chest with his weapon.

Officers are not encouraged to strike suspects with their guns.

The NYPD Patrol Guide doesn’t expressly prohibit hitting someone with a gun if he is resisting arrest or assaulting a cop.

“But it’s not encouraged for obvious reasons — your safety and the other guy’s,” another officer said.

Officials said investigators have not concluded if that is what happened — or if the bullet was fired during a struggle for the gun.