With a gun at his head and fear in his heart, a cab driver found his "lifesaver" to be a Berks County sheriff's deputy who happened to be in the right place at the right time.

Deputy Terry Ely was behind a Reading Metro cab that was stopped for the traffic light at North 10th and Buttonwood streets shortly before 4:30 p.m. Monday.

"It was a red light," Ely told 69 News. "It then cycled through to green. The car did not move, and it went back to red again. At that point, I just wanted to make sure everything was OK in the car."

At the same time, surveillance cameras inside the cab were rolling as a passenger in the backseat pulled out a gun, aimed it at the driver and demanded his money.

"Give me all your money, man... I need it all right now if you don't want to die," the masked man, later identified by police as Victor Martinez-Herrer, screamed to the driver.

"All hell broke loose," the driver, Ralph Valletta, told 69 News on Tuesday. "The gun came out at my head. He was screaming at me. He had his hoodie pulled down and I couldn't see anything but his eyes."

The panicked driver complied with the armed passenger's demands, handing over $11 from one of his pockets.

Moments later, the video shows Ely, the sheriff's deputy, activating his car's flashing lights and walking toward the stopped cab to investigate.

"I stood in the back to try and hear the conversation ahead of time so knew what I was getting myself into," Ely said. "At that point, I heard the driver say, 'Just please don't shoot me.'

The deputy, drawing his firearm, ordered Martinez-Herrer out of the vehicle and down on the ground as he called for backup from city police officers.

"Oh my God! You're a lifesaver," the relieved cab driver could be heard on video telling the deputy.

"He immediately stood up, ran over to me and gave me a hug and said, 'Thank you. You're a godsend,'" Ely recalled.

"I told him, I said, 'You need to go back to your station and get a cup of coffee and go home,'" Ely said. "His response was, 'I can't go home. I have bills to pay and I have calls to take.' To see someone that's just out there trying to work hard to make and to be victimized like that, my concern was all for him."

Authorities said they later learned that the suspect's firearm was a pellet gun equipped with fiber optic sights and the brand name "Ruger" on the pistol grip.

Video: Sheriff's deputy foils armed robbery

Valletta told investigators he believed the gun was real and that he feared for his life during the holdup.

"I almost had a heart attack in the car. My heart was beating," Valletta told 69 News. "You know, when that gun's pointed at your head, your body is doing things."

This is the third time, Valletta said, he's been robbed at gunpoint while on the job.

"I'm just glad he wasn't hurt," said Curt Stricker, president, Reading Metro Taxi. "Very bad situation."

Stricker said his company installed surveillance cameras in every one of its cabs in September 2014.

The 18-year-old Martinez-Herrera, who lives about a block from the scene, was charged with robbery, terroristic threats and simple assault. He was committed to the Berks County Jail on $100,000 bail.