A group of teenagers fought with a Costa Mesa police officer Tuesday afternoon, and one 16-year-old tried to grab the gun from his holster, officials said.

The officer was pulled into a scuffle when he responded to a call at a Ralphs grocery store at 380 17th St. at about 2:30 p.m.

Police did not identify the officer but said he was the first on the scene when several “uncooperative, hostile” minors were shoplifting, according to a news release from the Costa Mesa Police Department.

When he arrived, the four teens — two boys and two girls — were fighting with store employees near the cash register at the front of the store, police said.

The teens — who are all between 14 and 16 — had allegedly tried to steal liquor from the store.

The officer pulled one teen away from the group and handcuffed her, but while the officer was sitting her down, another came up behind him and tried to pull his handgun out of his holster, police said.

An off-duty Orange County Sheriff’s deputy who happened to be in the Ralphs store helped the officer by restraining and handcuffing the teen who had just tried to grab the handgun, police said.

A third teen then threw a punch when the CMPD officer grabbed him, police said. That left the officer with a bruise and cut under his right eye.

When a second Costa Mesa police officer arrived, the two members of the force wrestled that teen to the ground, gaining control of the situation, according to the news release.

Other officers also arrived and took the fourth teen into custody.

The injured officer received stitches at Hoag Hospital, police said.

All four teens were booked into the Costa Mesa Police Department on suspicion of conspiracy to commit robbery.

Three were also booked on suspicion of resisting an officer; one also faced a charge of assaulting an officer and another, attempting to take a firearm.

Three of the teens live in Costa Mesa, and the fourth lives in Newport Beach, police said.

They are being held without bail, according to the news release.