A man accused of gunning down his corrections officer ex-gal pal planted a GPS device on her car to track her in the days before her death, Brooklyn prosecutors said Thursday.

Keon Richmond, 37, is accused of pumping five rounds into Alastasia Bryan, 25, on the night of Dec. 4, 2016, as she was visiting friends and family in Canarsie before driving to her shift on Rikers Island.

Richmond tracked his ex-lover’s movements for three days before he gunned her down as she sat in her car outside the Flatlands home around 9:15 p.m., Kings County Assistant District Attorney Olatokunbo Olaniyan told a jury during her opening statements.

“Unbeknownst to her, as she went about her ordinary tasks, everything she was doing was being followed, was being monitored, was being tracked,” Olaniyan said of the device affixed to Bryan’s Infiniti sedan.

“He waited and waited until the moment was just right,” she said.

Richmond was apparently enraged over losing a white BMW that Bryan leased for him in her name while they were dating between 2014 and 2015.

Bryan allowed him to continue using the car after they split, but alerted the NYPD in August 2016 when Richmond began falling behind on payments.

Olaniyan said Richmond was driven by “resentment” for Bryan when cops seized the car, and that the “resentment turned to retaliation” — calling his ex up to 41 times from a blocked number before he “lost control” and allegedly murdered her.

Defense attorney Gregory Watts tried to poke holes in the prosecution’s case and maintained that Richmond’s fingerprints and DNA were never found on the GPS device retrieved at the scene.

“Mr. Richmond couldn’t get back his car, so he killed her,” Watts said mockingly. “He had no reason to murder her.”

Richmond, dressed in a black suit and wearing his hair in braids, was in court but said nothing as he sat next to his lawyer.

In his opening statements, Watts said Bryan was killed by an “unknown assailant” and accused authorities of giving the case special treatment because Bryan was an academy graduate.

Trinidad-born Richmond — an illegal immigrant with a lengthy rap sheet — evaded deportation for 11 years after overstaying his tourist visa, The Post revealed after Bryan’s murder.

Watts said police relied on surveillance video from the scene in which the license plate on the getaway vehicle cannot be seen and in which Richmond could not be positively identified.

“Since Alastasia Bryan was a corrections officer, the NYPD goes full gung ho in an attempt to solve this crime,” he said.

Bryan had only just graduated from the academy on Nov. 1, family told The Post.