PRETORIA, South Africa -- South African Olympic athlete Oscar Pistorius on Thursday denied that he pulled the trigger of a gun that went off in his hand in a crowded upscale restaurant last year, a contention dismissed by the prosecution as impossible.

On trial in Pretoria’s high court on charges that he murdered his girlfriend, Reeva Steenkamp, he also flatly denied firing a gun out of the roof of a car in 2012, although two witnesses, ex-girlfriend Samantha Taylor and former friend Darren Fresco, testified that he had.

Explaining how he fatally shot Steenkamp, Pistorius said he accidentally fired through the door of an enclosed toilet in his home in the early hours of Valentine’s Day after hearing a noise within.

Grilled by state prosecutor Gerrie Nel on whether he aimed at the toilet door and fired accidentally or intentionally, Pistorius became confused.

“I’m getting confused with this accidentally or not accidentally. I don’t understand, my lady,” Pistorius said, addressing Judge Thokozile Masipa.

He had his gun loaded but did not intend to shoot through the door into the toilet, where he believed an intruder or intruders were, Pistorius testified. He fired when he heard a noise that he interpreted to mean he was being attacked.

But he admitted that he had no reason to shoot, given that there was no intruder. And he agreed with Nel that there may have been no shooting if he had waited a minute or if Steenkamp had spoken.

Nel relentlessly painted a portrait of a self-absorbed young man who wouldn’t take responsibility for wrongdoing, was negligent with firearms and ammunition and didn’t recognize a police officer’s right to confiscate a loaded gun that he had left unattended on a car seat.

Twice, Pistorius seemed to refer to inanimate objects as if they were human. His gun safe “possessed items that belonged to me and my father,” including .38 caliber ammunition for which he had no license. At another point, he said a Glock pistol in his hand fired by itself at a restaurant, repeatedly insisting that he had not pulled the trigger.

A ballistics expert testified that the gun could not fire unless the trigger was pulled.

When the prosecutor told him that it was illegal to keep the ammunition in his safe without a license, Pistorius responded, “it’s not my understanding of the law.”

“This is the second time today,” Nel mocked Pistorius over his possession of the ammunition. “First,  we had the miraculous discharge of a gun. Now, when I say it's illegal, you won't accept it.”

Nel also revealed that Pistorius’ father, Henke, refused to sign a police statement confirming that the ammunition was his.

Pistorius has pleaded not guilty to the murder of Steenkamp, to unlicensed possession of .38 caliber ammunition and to two counts of recklessly discharging the firearm at the restaurant in 2013 and out of the sunroof of the car in 2012.

In addition, Pistorius said Steenkamp “exaggerated” in a WhatsApp message to him complaining that he threw public tantrums and picked on her incessantly.

“I didn’t pick on her in any way. I was good to Reeva,” the athlete said. In the same message, Steenkamp complained that the way he snapped at her was frightening.

“Reeva was never scared of me, my lady,” Pistorius said to the judge. “I’ve never lost my temper or shouted at her. There could have been other occasions when I snapped at her.”

Pistorius admitted he accused her of flirting with a male friend.

“I guess I was a bit jealous and insecure," he said. "She said she was not flirting with anyone. I did think she was.”

He accused former friends Taylor and Fresco of lying that he fired out of the sunroof of a car on the way back from a social outing to the Vaal River