Image copyright AP Image caption Sgt Tom Smith had worked at Bart for 23 years and was in charge of its detective squad

Police are investigating why a San Francisco-area transport police officer shot and killed a colleague during a search of a suspect's apartment. 

Sgt Tom Smith, 42, was the first officer of the Bay Area Rapid Transit (Bart) police to be killed in the line of duty in the force's 42-year history. 

He was killed on Tuesday as a squad of officers searched the home of a robbery suspect who was already in custody. 

Investigators say Sgt Smith was shot accidentally. 

Sgt Smith is survived by his wife, also a Bart officer, and a six-year-old daughter. 

Bart is a commuter rail line that serves the San Francisco Bay area in northern California. 

In a joint statement, Bart's police chief Kenton Rainey and general manager Grace Crunican said, "The entire Bart organization is deeply saddened by this tragic event." 

Mr Rainey did not name the officer who shot Sgt Smith, but said he was "extremely upset". 

"We want to give him and his family a chance to come to grips with what's going on and what's happening," he told reporters. 

Sgt Smith and several other Bart officers were wearing bulletproof vests during a search for stolen items in an apartment in Dublin, California, according to Sgt JD Nelson of the Alameda County Sheriff's Office, which is investigating the shooting along with the Bart police department and other agencies. 

After two knocks went unanswered, they opened the unlocked door, with guns drawn. 

Soon after, one officer fired a shot, striking Sgt Smith, he added. 

Sgt Smith was taken to Eden Medical Center in Castro Valley, where he died.  He had served on the force for 23 years and was in charge of its detective unit.