A sheriff's deputy was shot and killed at point-blank range while in the line of duty Sunday in Northern California, police said.

Stanislaus County Sheriff Adam Christianson said that Deputy Dennis Wallace, a 20-year veteran of the force, was shot twice in the head around 8:30 a.m. while investigating a suspicious person and vehicle near a fishing access spot in Hughson, a city roughly 10 miles outside of Modesto.

"He was executed," Christianson said. "We believe that Deputy Wallace was killed outside of the car, and we know for a fact that the gun used in this crime was in direct contact with his head when the trigger was pulled twice."

The suspect, who has been identified as 37-year-old David Machado, fled the scene and carjacked an escape vehicle in the nearby city of Ceres, Christianson said. Machado was later apprehended in Tulare County and brought into custody by police Sunday afternoon.

Stanislaus County Sheriff's Department

Before being captured, police said Machado committed an armed robbery at a convenience store in the city of Lindsay. He tried to swipe a woman's purse, but she was able to resist and alert police.

Machado fled the scene on foot, but law enforcement officers were able to track him down and detain him just after 12:30 p.m. without any problems.

Lindsay officers didn't initially recognize Machado as the suspect in the killing of Wallace. But once he was in custody, they identified him through tattoos and a photograph and immediately contacted the Stanislaus County Sheriff's Department, Christianson said.

It was not immediately clear if Machado had an attorney.

Despite the capture, Christianson was visibly upset to report another officer's death.

"It's time to stand united," he said. "It's time to stand together with public safety and with law enforcement to stop what's happening in our nation."

Wallace, 53, dedicated some of his time with the police force to working with early intervention, prevention and education programs. He leaves behind a wife and family, Christianson said.

"(Wallace) had a very special relationship with young people and a special place in our hearts at the sheriff's office," Christianson said. "We need to keep the Wallace family in our thought and prayers. We need to keep law enforcement in our thoughts and prayers."

Wallace lived and worked in Hughson, where he was involved in youth soccer, refereeing football and serving as a liaison between schools and law enforcement.

Wallace is the fifth law enforcement officer in California to die in the line of duty in the last five weeks. The slaying comes after a deputy in Modoc County was killed while responding to a call about a disturbance, two Palm Springs police officers were shot to death during a domestic disturbance call and a Los Angeles County sheriff's sergeant was shot and killed in the high-desert town of Lancaster while answering a burglary call.

The Associated Press contributed to this report.