The Catalan police, who patrol the region of Catalonia around Barcelona, in northeastern Spain, showed a video on Twitter of the incident on Thursday and it has since been seen more than 220,000 times.
The video, shot by store CCTV, shows the male officer restraining the suspect from behind, forcing him to the floor, and then removing a knife from his right hand.
The suspect, aged 47, is in jail on suspicion of armed robbery. He has a prior record of similar crimes, the police said in a statement.
The off-duty officer has been with the police force, known as the Mossos, for some time, the Catalan police press office told CNN, without specifying how long.
He had just entered a supermarket in his neighborhood in the town of Mataró, northeast of Barcelona, around 4 pm local time when he noticed the suspect standing next to a nervous-looking store employee at the open cash drawer.
The officer asked the employee if everything was OK, but it was the suspect who answered, saying everything was fine, according to the statement and the police press office.
The officer took a few steps to get right behind the suspect and grabbed him. They struggled and fell to the floor. In the suspect’s left hand was cash, the statement said.
The off-duty officer, lying on top of the suspect, identified himself to others in the store as a police officer, and police reinforcements arrived quickly. The store employee was not injured in the attempted robbery, which took place on Monday, the statement said.