The cricketer admitted he downed 12 or more drinks before he knocked out two men in a street brawl but denied he had been drunk, aggressive or homophobic.
Stokes said: "I was told by Mr Ali along the lines of 'Shut the f*** up or I will bottle you'.
"As soon as I see Mr Ali swing the bottle at someone and physically hit them with it, that's when I took the decision that I needed to get involved.
"I took a swing at Mr Ali. He had run past one of my friends, who I have known for a long time, with the bottle, attempting to hit him and then actually struck someone with the bottle.
"I was trying to stop Mr Ali from doing damage to anyone with a glass bottle."
The England star, 27, had four beers and eight vodka and lemonades as he celebrated his team's win over the West Indies in Bristol last September.
Stokes, who was called the 'main aggressor' by a police officer who saw him shatter a man's eye socket, told the jury: "I was protecting myself. I took the decision very quickly. I knew not just myself but other people could be a target of either of these two men".
It came as police body camera footage showing the moment Stokes was arrested and put in handcuffs was released today.
This morning defendant Ryan Hale, 28, walked free after trial judge Peter Blair QC told Bristol Crown Court "there has been no evidence whatsoever" he was guilty of affray.
Hale told the jury he feared for his life when Stokes attacked him and his friend Ryan Ali, 27, claiming he was an 'innocent bystander getting assaulted brutally for nothing'.
The former soldier said he was knocked out cold and said: "I thought he could have killed me. I don't know why he didn't stop. He could have beaten the living hell out of me".
He added: "I was in the Army, I know what self-defence is, you can use reasonable force. If someone is with a bottle and you want to stop it, once you've disarmed him that's it".
PC Stacey Alway told him: "A guy over there was covered in blood and I've been told you punched him".
Stokes then says it was because they were "abusing my two friends for being gay" and then asks for his handcuffs to be loosened.
The cricketer this afternoon started giving evidence about why he left two men unconscious during the drunken street brawl following England's win over West Indies earlier that day.
Stokes swore on the Bible before beginning his evidence.
He said that after the match the team went out into Bristol city centre.
After the game he drank a beer, but had to drive so didn't have a lot.
He drove from the cricket ground to the hotel, where he, his wife Clare and some team-mates had dinner and he drank two or three pints of lager .
He drank 'five or six vodkas' at Mbargo in the Clifton Triangle, where they left teammates Liam Plunkett and Jonny Bairstow.
The cricketers stayed between 45 minutes and an hour at Pryzm, and Stokes said he would have had 'more than one' vodka and mixers.
He then returned to Mbargo again he and Hales were not allowed in because it was after 2am.
Stokes said doorman Andrew Cunningham told them they would not be allowed back in.
"(He was) pretty blunt," Stokes said.
Asked about offering Mr Cunningham money, Stokes said it would have been around £60 or £70 but not £300.
"I would say it was £60, £70. I would say 'If we give you some money can we come in?'. (He said) 'No, you're not getting in'," Stokes said.
Describing Mr Cunningham's tone, the cricketer said: "It was still blunt but there was definitely a change in his attitude from when we offered him money to get back into the club.
"The tone and the way he was speaking to us just changed. It went from being just blunt and started to be a bit more...
"It was like he had something against us because we had offered him money to get back in."
Stokes added: "I didn't use the c-word towards him. I said to him 'Come on mate, I've got s*** tattoos as well, let us back in'."
Mr Cole asked Stokes to explain the reference to 's*** tattoos' and he replied: "I am constantly getting told by teammates and by who I play with that I have got s*** tattoos."
The prosecution claim that Stokes turned his attention to two gay men, William O'Connor and Kai Barry.
Mr Stokes denied flicking a cigarette butt at Mr Barry and Mr O'Connor or mimicking them because they were 'camp'.
He said he been wearing black ripped jeans, a green t-shirt and white Buscemi high-top shoes with gold padlocks on the back.
"My attire on that night got mentioned," he said. "It was one of the gay couple."
When asked if his exchanges were 'homophobic', he said: "No, definitely not".
He said they were discussing what they were all wearing and told: "I get told by quite a lot of my teammates that I dress the worst in the team. The only comments between myself and the gay couple was what we had chosen to wear that night".
The jurors watched the CCTV clip of what appears to be Stokes flicking a cigarette butt towards one of the gay men.
"I don't remember flicking a cigarette towards anyone," he said.
"Obviously, it looks like I have thrown something in the direction of one of those two gentlemen."
He said before leaving he shook the hand of one of the two doormen, but Mr Cunningham refused to accept his hand.
He and Hales then walked away and were planning to find a casino with the help of Mr Hales' iphone.
He recalled looking back when he walked by Ali, Mr Hale, Mr O'Connor and Mr Barry. Stokes said moments later he witnessed a confrontation and shouting between the four people.
He said Ali and Mr Hale were shouting homophobic comments at Mr O'Connor and Mr Barry, who were combating verbally what was being said to them.
He said at the time he was looking for a taxi.
Stokes told the jury he addressed Ali and Mr Hale, saying: "You shouldn't be taking the p*** because their gay.
"I was told by Mr Ali something along the lines of 'shut up or I'll bottle you'.
"I then went on the same lines as they shouldn't be saying what they were saying because they were gay."
Ryan Hale told police he and Ali had been out celebrating his promotion at work and had left Mbargo when the nightclub closed.
"The first thing he did was put his hand on my k**b. I'm an ex-soldier, to me its banter," he said.
"It did not offend me at all. He was pinching my arse and I grabbed him and said 'You're coming home with me'. He said 'Just because I'm gay doesn't mean I'm going home with any other bloke'. I was like, it's fine, no problem and just carried on walking."
Hale added: "I remember two guys coming from the road and I remember saying 'I don't want no trouble'. I don't remember which order it was in. 'I don't want no trouble'.
"I am telling him to stop. He is having a go at Ryan and I am trying to stop any fight, to stop him getting hurt.
"That's the moment I get smashed to the face".
Hale said Mr O'Connor and Mr Barry - the men he is accused of abusing - pulled him to help him up.
Stokes told police he felt 'under threat of immediate attack' moments before he beat two men senseless on a drunken night out in Bristol.
He again asserted in an official police statement hours later that he had intervened when he overheard Hale and Ali verbally abusing Kai Barry and William O'Connor - who Stokes had never met before - in the street.
He said tempers flared when Ali told him: "Shut the f*** up and f*** off or I'll bottle you."
He described how Ali lurched towards him brandishing a bottle, before Hale grabbed him from behind, and would later be seen clutching a metal pole.
"I felt the need to defend myself," he said in his first police statement hours after the fight. "I felt I was going to be attacked. I didn't feel I had an option to leave in the heat of the situation.
"Obviously it all happened very quickly but I am clear that I felt under threat of immediate attack from both these men and I did what I did only in order to defend myself."
But community support officer Andrew Spure, who was at a colleague's leaving do at Mbargo nightclub in Bristol at the time, claimed Stokes was the 'main aggressor'.
In his statement written hours later, Mr Spure told how he had left the club and "saw a group of people fighting", adding: "One of the males struck the other in the head with a clenched fist".
Bristol Crown Court heard it was Stokes who had struck Ali, knocking him to the floor and leaving him with a shattered eye socket.
Asked about separating Stokes and Ali, Mr Spure said: "The individual seemed to be the main aggressor".
He said Ali 'seemed to be trying to back away or get away from the situation' before he was punched by Stokes.
Stokes told police he had drunk 'two or three' pints and five vodka-mixer drinks on the night of the ruckus in Bristol's upmarket Clifton area on the night of September 24 last year.
The England and Durham star faces a single count of affray alongside co-defendants Hale and Ali.
Stokes and teammate Alex Hales were together celebrating with the England cricket team, who had just beaten the West Indies in a one-day international in Bristol, when the fight happened.
Jurors at Bristol Crown Court yesterday heard Stokes' police statements, which were made in the weeks after the fight.
In them, he told how he and Hales had been walking towards a casino when they overheard Hale and Ali verbally abusing Mr Barry and Mr O'Connor.
He said: "They weren't shying away from it but they were obviously offended by the abuse being levelled towards them. What Ali and Hale were saying was far from harmless banter, it was nasty homophobic abuse."
Stokes said he intervened and told Ali and Hale: "Leave it out - you shouldn't be taking the p*** because they're gay". He claimed Ali replied: "Shut the f*** up and f*** off or I'll bottle you".
The all-rounder said when he saw Ali hit Mr Barry, "I decided that at this point matters had become too serious to ignore and that I had to intervene to stop Ryan Ali".
Stokes said he scuffled with Ali on the floor before Hale, also holding a bottle, got involved. "At this point, I felt vulnerable and frightened. I was concerned for myself and others," he claimed.
"The force I used in defending us was reasonable and entirely justified when the circumstances are viewed objectively," he added.
However, in his police statement Ali said he was the one who 'felt threatened' by Stokes.
He told officers: "I can't recall what happened but from watching the video I seem to be in a defensive stance, as though something has happened prior to this video... I believe I felt threatened and it can clearly be heard.... I've got the bottle up and I'm saying 'move back, move back'.
"I'm not trying to attack anyone with the bottle, I'm purely saying 'get back, move away'. I believe I was being threatened or I felt threatened and that's the reason."
The brawl left both men unconscious, and Ali with a fractured eye socket. Jurors were shown graphic photographs of their injuries taken in hospital shortly after.
And they were shown video footage from the body-worn camera of PC Stacey Alway, the officer who arrested Stokes at the scene of the bust-up.
In the video, PC Alway tells Stokes: "A guy over there was covered in blood and I've been told you punched him."
Stokes replies: "Because he was abusing my two friends for being gay."
He is swiftly handcuffed and put in the back seat of a marked police car. He asks the officer to loosen his right handcuff three times, at one point asking: 'Are there any sort of cameras around?'
Fellow England cricketer Alex Hales - who is alleged to have kicked Ali in the head but is not on trial - told PC Alway: "I came after you guys turned up."
When she told him to leave the scene, Mr Hales replied: "I feel bad. He's my best friend. I saw him after everything happened."
He was interviewed under caution, but not charged.
The court previously heard allegations that Stokes bullied the two gay revellers, throwing a cigarette at one and making mocking gestures at them, after swearing at a bouncer at the Mbargo club.
Stokes and Ali deny affray. Hale was cleared. The trial continues.