The Santa Clara Police Department and the Santa Clara County Sheriff's Office were working the covert drug probe when the shooting took place around 3 p.m., according to Sunnyvale Department of Public Safety Capt. Dave Pitts.
The sheriff's office reported on Twitter that one of its deputies was involved in the shooting and that Sunnyvale police are handling the investigation.
The man, whose name has not yet been released, was transported to a hospital and was later pronounced dead.
The shots were directed at the suspect inside the parking lot of Hobee's restaurant at 800 W. Ahwanee Ave., near Mathilda Avenue and U.S. Highway 101, Pitts said.
Sunnyvale police officers knew about the operation in advance and were in the area to provide assistance, Pitts said.
No one else was injured in the shooting and the investigation into it is in the early stages, Pitts said.
A clerk at a Motel 6 at 806 W. Ahwanee Ave. said he heard about 15 gunshots and then a saw a wounded person being transported from a pickup truck.
The clerk, John Carroll, 69, said he heard shots ring out at about 2:30 p.m. outside the Hobee's restaurant. He said he then saw police cordon off the scene.
"They pretty much shut down the area pretty quickly," Carroll said.
The pickup had bullet holes in the windshield and on both the driver's and passenger's sides, Carroll said.
"As many shots that were fired, it's hard to believe" that the suspect survived, Carroll said.
Two lanes of North Mathilda Avenue were blocked during the preliminary investigation, according to police.
Investigators worked the fatal shooting in the Hobee's parking lot for close to 8 hours as they closely examined the white pickup truck with a shattered driver's side window.
ABC7 News contributed to this report.