A Montgomery County sheriff’s deputy fatally shot a motorist on Saturday morning after the man caused two car crashes and attacked the deputy with a large piece of wood, Sheriff Darren M. Popkin said.

The dead man was identified by authorities Sunday as Kevin Costlow, 52, who lived in the Montgomery town of Laytonsville, close to where the incident occurred. The deputy’s name has not been made public by county police, who are investigating the shooting.

Beginning about 8 a.m., Costlow had been driving erratically in a Volkswagen sedan heading out of Laytonsville, according to Popkin and Sgt. Rebecca Innocenti, a county police spokeswoman.

One driver swerved off the road to avoid him, crashing into a telephone pole. Costlow then crashed head-on into a second vehicle at the intersection of Olney Laytonsville Road and Fieldcrest Road, officials said.

The crashes and the strange driving led several people to call 911.

Popkin said the Volkswagen rolled on for about 20 feet after the second collision. Costlow then got out of his car and used a large piece of wood to try to attack the people he had just crashed into, Popkin said.

The sheriff’s deputy was driving to work in Rockville and either heard about the 911 calls or just happened to be passing, Popkin said. He stopped at the scene to help when Costlow allegedly turned on him.

Popkin said the deputy appears to have unsuccessfully tried to use his Taser to stop the assailant, who continued to attack with the piece of wood.

“It was at that point the deputy felt his life was threatened and did use force that did stop the individual,” Popkin said in a news conference near the scene.

A one-minute video, recorded by a bystander who had pulled up to the scene and was sitting in his car, starts with the deputy and Costlow standing along Fieldcrest Road, where it meets Maryland Route 108. The deputy has his gun drawn, pointing it with two hands towards Costlow. They stand about eight feet apart, according to the video, which was obtained by The Washington Post.

Costlow can be seen bending over and picking up what appears to be a sturdy tree branch, about three inches thick and more than four feet long, and walking toward the deputy.

They cover more than 20 feet, Costlow walking forward, the deputy walking backward. Eventually, Costlow lifts the branch over his head and slams it down toward the deputy’s left shoulder.

About three seconds pass as Costlow continues forward and the deputy continues backward. Costlow raises the branch over his head again. As he brings it down, the first gunshot is heard on the video. Costlow continues walking toward the deputy, who continues backing up, as the video records what sounds to be a rapid series of gunshots. The video records Costlow falling to the pavement.

The deputy was treated at a hospital for a back injury and superficial wounds to his arms that he suffered as he tried to protect himself, Popkin said. No one in the other vehicles suffered injuries that required being taken to a hospital.

“My thoughts are with everybody who was involved in this incident,” Popkin said.

Montgomery County police are leading the investigation with help from the Howard County State’s Attorney’s Office, following typical practice for shootings involving Montgomery law enforcement officers.

Between the crashes and the shooting, police were dealing with a crime scene spread along two miles of Olney Laytonsville Road.

“This is quite involved. It’s extensive,” Popkin said. “Montgomery County police have incredible experts that are involved in every aspect of this sort of investigation.”

The sheriff’s department is typically responsible for maintaining security at courts, aiding with evictions and serving legal papers. The sheriff himself is elected, and Popkin is a Democrat.

Montgomery County Police Chief Marcus Jones said investigators were trying to find witnesses to determine what might have caused the incident.

“There’s more to the story due to the erratic behavior of this gentleman to include his driving and his behavior when confronted by the deputy sheriff,” Jones said.

Paul Duggan contributed to this report.