“Before I knew it, I had fired four shots at the door,” he said.
The trial of the athlete, who could face life imprisonment if convicted of murder, was adjourned until Wednesday after he broke down crying.
The 27-year-old double amputee denies deliberately shooting Ms Steenkamp on Valentine’s Day last year.
On his first day on the stand, on Monday, he made a tearful apology to Ms Steenkamp’s family.
The prosecution alleges that Mr Pistorius killed his girlfriend after an argument with her.
‘She wasn’t breathing’
In the early hours of 14 February 2013, he said he had got up from bed to bring in some fans he had left outside, in order to cool his bedroom.
When he heard a window opening in the bathroom, he said, he thought there was a burglar trying to get in.
Wanting to protect Ms Steenkamp, who was not sleeping, he had gone to get his gun in the dark.
“I whispered to Reeva to get down and phone the police,” he said.
He said he then went into the passage without his prosthetic legs and, overcome with fear, started screaming, and shouted for Ms Steenkamp to get to the floor.
The toilet door slammed, reconfirming his belief there was a person or people in the bathroom, the athlete said.
“I heard a noise from inside the toilet, what I perceived to be someone coming out of the toilet,” he said tearfully. At that point, he shot at the door.
After the shooting, Mr Pistorius said he had smashed in a door panel to get into the toilet, where he discovered what he had done.
“Whilst I leant over the partition to get in, I saw the key, so I took it and I unlocked the door, and I flung the door open, and I threw it open,” he said, sobbing.
“And I sat over Reeva and I cried… and um, I don’t know how long… I don’t know how long I was there for… She wasn’t breathing.”
As the athlete broke down, the judge adjourned the trial.
Earlier, the athlete described how the couple had spent a quiet evening together on 13 February, Ms Steenkamp doing some yoga as he spoke to his cousin on the phone.
He had then watched TV in bed with his head resting on her stomach and she would occasionally show him photos of cars she was looking at on her phone, he said.
He said that they had bought Valentine’s Day gifts for each other. He had bought her a bracelet and they had been due to go the jewellers’ to collect it the next day, he said.
Mr Pistorius also faces charges of illegally firing a gun in public and of illegally possessing ammunition, which he denies.
There are no juries at trials in South Africa, and his fate will ultimately be decided by the judge, assisted by two assessors.
Ms Steenkamp, a 29-year-old model, reality TV celebrity and law graduate, was hit by at least three bullets while in the toilet cubicle of Mr Pistorius’ home in Pretoria.