MIAMI-DADE COUNTY, Fla. – A South Florida man accepted a plea deal Wednesday, more than a year after he shot a Miami Gardens police officer as the officer was sitting in his patrol car.

As part of the plea deal, David Mejia will serve four years in prison followed by 10 years of probation. He must also undergo a mental health evaluation.

Police said Mejia ambushed Officer David Starling Jan. 22, 2016, near Northwest 183rd Street and Northwest Seventh Avenue while Starling was writing up a crash report in his patrol car.

Former Miami Gardens Police Chief Antonio Brooklen said the officer was filling out the report when a black BMW sport utility vehicle passed by and the driver "backed up and ambushed the officer."

The officer was struck once, but he got on his police radio, called for backup and gave a description of the SUV, Brooklen said.

As other officers joined the pursuit, the suspect "leaned out the window with a firearm and began to fire at the officers," Brooklen said.

The SUV crashed at Northwest 183rd Street and Northwest 32nd Avenue. The suspect ran off but was later caught in a nearby backyard, Brooklen said.

Starling was taken to Aventura Hospital.

He appeared in court Wednesday for Mejia's hearing.

Mejia faced 25 years to life in prison if a jury had convicted him of attempted murder of a law enforcement officer.