The officer was just about to get into his car to leave when the alleged robbery took place.
Police and doughnuts have joined forces for the greater good this week after a quick run to Dunkin' Donuts led an officer to stop an alleged robbery in Boston.
Police officer Jose Diaz said he was almost finished with his order at Dunkin' Donuts in Andrew Square when a man, allegedly identified as 51-year-old Stephen M. White, walked in and adamantly asked to use the restroom, which the cashier said was not available to the public.
Read: Woman Saves Man's Life on Their First Date When He Stopped Breathing
Diaz told the man he knew of a public restroom nearby, grabbed napkins and was heading back to his cruiser in the back parking lot, when the clerk suddenly ran out, exclaiming, "He's robbing us, he's robbing us!"
Diaz dropped his coffee, called it in on his radio and got to work, moving to the front and arresting the man, who had a bag of the stolen cash. Diaz said the man threatened to shoot the employees, who looked "terrified."
Read: Man Allegedly Robbed 80-Year-Old While She Visited Late Husband's Grave
Regarding the odd decision for the man to rob the store when the police officer was so close, Diaz said it was "just bad timing," and that he always has to be ready for any unpredictable situation.
"You never know when something can happen," said Diaz. "Some crazy 911 call can come in when you are at the station, out on patrol, or even at Dunkin' Donuts."
Diaz said it was a fateful encounter, as he had stayed in the office later than normal on Wednesday to help a co-worker with reports before making a usual coffee run. Had he left at normal time, the encounter would not have happened.
"That got me to the Dunkin' Donuts a little later for the coffee run," Diaz said. "I happened to be there when this guy showed up."
White is being charged with unarmed robbery and threats to do bodily harm, police said.
As a sign of appreciation, the Dunkin' Donuts employees replaced the officers dropped coffee order for free.
"Obviously, that was an awesome token of appreciation," Diaz said. "These are A-1 folks. Even if I had just tripped over my laces and spilled my order, they would probably give me a new one."
Watch: Man Caught on Camera Trying to Kidnap Baby From Dunkin' Donuts: Police