A Virginia driver and police officer were nearly hit on the side of a highway when a BMW driven by a teenager spun out across the median and slammed into the car, coming within inches of killing the officer, authorities said.

The 17-year-old driver of the BMW M3 was charged with reckless driving, Fairfax County Virginia police said Tuesday.

The incident began Monday morning when the officer pulled over a gray BMW sedan on Fairfax County Parkway, about 25 miles west of Washington, D.C., Fairfax County, Virginia, police said.

Dashcam video shows the officer talking to the sedan’s driver through the passenger-side window when a black BMW M3 comes into view as it speeds around the corner of the parkway and loses control.

The officer recognizes the threat and begins to run back toward the patrol car when the BMW M3 careens into the sedan and appears to clip the officer in the leg.

After the collision, the officer immediately radioed in emergency crews and checked on the sedan’s driver.

Both the officer and the sedan’s driver escaped with minor injuries, as did the driver of the M3 and the two passengers in that car, police said.

The 17-year-old driver of the BMW M3 was charged with reckless driving, police said.

More coverage from USA TODAY