A Cape Cod police officer has died after being shot in the head by a career criminal while he served an arrest warrant with his dog.

K-9 officer Sean Gannon, 32, was slaughtered by Tom Latanowich at around 3.30pm on Thursday in Barnstable.

Gannon was one of many officers who were engaged in a standoff with Latanowich at a home in the town.

They were trying to arrest him for firearms offences when he suddenly shot the police officer and his dog Nero.

Gannon died in hospital and his dog is still being treated by veterinarians.

Latanowich's lengthy rap sheet included arrests for drugs, gun offenses and a 2016 stabbing. It is not clear why he was allowed out of custody given his historic criminal behavior.

Officer Sean Gannon was shot in the head and his dog Nero was injured by career criminal Tom Latanowich (right) on Thursday while they tried to serve a warrant to arrest him for firearms offenses

No one from Yarmouth Police Department would answer questions about his history or about Gannon's death on Thursday.

A spokesman told DailyMail.com that all of the officers were 'grieving' and making funeral arrangements.

Latanowich was on probation when police tried to arrest him on Thursday.

After shooting Gannon, he was charged with murder.

Last year, Yarmouth Police Department described him as a 'violent and notorious career criminal'.

He was arrested in 2016 for stabbing a man while out on bail for other offenses.

The department mourned the loss of Gannon, who was not thought to have been married, on social media on Thursday night.

Gannon had worked on the force for eight years and was an avid anti-drugs campaigner, friends said

Latanowich was holed up in this home in Barnstable and was engaged in a standoff with police when he suddenly fired at Gannon

'With deep sorrow and heavy hearts the Yarmouth Police Department reports the loss of Officer Sean Gannon.

'Officer Sean Gannon was killed in the line of duty today.

'We must tend now to his family and the needs of our department and our community,' the department said in a Facebook post.

Gannon had been part of the force for eight years. Friends are now raising money to launch a college scholarship in his name.

In a description on the GoFundMe page, a friend described him as the first full time drug K-9 officer in Yarmouth.

Friends are now raising money to launch a college scholarship in Gannon's name. It remains unclear why Latanowich was on the streets despite his lengthy rap sheet which included a 2016 stabbing

He was dedicated to ending the opioid epidemic in the area, they added.

'He was on the streets every day, not just trying to make arrests, but engaging in door-to-door community outreach by offering addicts help in obtaining treatment.

'He believed in this approach to policing.

He was out in the community knocking on doors, attempting to connect addicts with the resources that could help them get off drugs.

'In his own words: “One of the best ways to combat the drug problem in our town is not to just catch people with drugs, but to convince people that use drugs to stop using them,"" it said.

They hope to raise $50,000.