This is the moment a bakery employee outsmarted an armed thief and had him begging for mercy after locking him inside a shop in Mexico.

Viral footage showed the suspect confronting a female worker at Tere Cazola on Monday afternoon in Campeche, a port city in the Gulf of Mexico.

The man immediately told the woman, 'This is a robbery. I am armed,' as he lifted his shirt and made his way to the cash register.

The woman remained calm despite the threat of violence and stepped to the side.

'Give all of the money. All the money,' the suspect instructed the woman, who distanced herself away from him with an exit strategy already in place.

A thief confronts a worker during a botched robbery at the Tere Cazola bakery in Campeche, Mexico, on Monday. The suspect was outsmarted by the employee, who walked away from the counter while he searched for her cellphone before she lowered the store gate and locked it

A bakery thief attempts to open the shop gate after a worker lowered and locked it during a failed robbery attempt in Campeche, México, on Monday

He briefly disappeared from the view of one of the surveillance cameras and told the pastry shop employee, 'I don't give a **** that they're recording me.'

The suspect appeared to lose his patience when he asked the woman for her cellphone and was unable to find it near the register.

It was at that moment that the worker took advantage that he was still searching for the phone when she walked outside.

She quickly reached for the gate and brought it down before locking it.

The bakery worker took advantage that the thief was searching for her cellphone and exited the shop before she lowered and locked the gate to trap the suspect inside

The desperate suspect moved a shelf and placed it behind the shop's gate in an attempt to prevent anyone from entering before he tried to climbed through a broken window in Campeche, México, on Monday. However, police were waiting outside and arrested him

The trapped perp briefly attempted to lift the gate and begged to be let out.

'Juanita, help me, help me,' he shouted.

The recording showed the suspect pacing around the shop trying to figure out how he was going to escape.

At one point he placed a wooden display shelf behind the gate to stop anyone from coming inside.

He then grabbed a fire extinguisher and smashed open window that he was able to climb out through, but was promptly arrested by cops who were waiting outside, El Diaro de Yucatán reported.