We should really get rid of those myths. Yes Socrates was executed. Yes he was teaching students philosophy/science (there was no difference in antiquity). The guy who told his story was a student of his, a big fan of him, and absolutely did not agree with the judgement of the people, but there's a huge but here:
You may want to google "thirty tyrants" and read a bit and you'll quickly see there's more to the story. The claim is that Socrates was executed for constantly criticizing the state, for putting science and philosophy/ethics ahead of the interests of the state, and thereby corrupting youth and his students. That, taken in 20th century context sounds bad, really, really bad. However, here's what they meant by that statement : not once but twice the people he taught tried to overthrow the state. You see, Socrates hated democracy with a passion, to the point that he advocated using mass violence and killing to end it.
One of these coup attempts by his students succeeded and proceeded to execute >5% of the total population of Athens in a little over a year for various imagined offences. One of the tyrants, their leader if they had any, a relative and pupil of Socrates is described as "determined to remake the city and kill democracy whatever the cost in lives". While Socrates distanced himself from their actions, and even managed to make enemies of some of them, there's good reason to believe he was involved.
When the tyrants were overthrown, democracy was reinstated, and Socrates was left unpunished on condition of not teaching anymore. It didn't take him a week to violate this condition, and once again he raged against the state and it didn't take long for his students to attempt yet another coup. Shortly after that coup attempt was thwarted, again with loss of life, he was executed, right after his students who attempted the coup and survived were.
Socrates was a man who believed, taught and fought for the idea that "those in the moral right" (and he meant him and his students) should control all of society, and he kept fighting for it after having demonstrated what happened (ie. the killing of >5% of Athens).
Was this guy executed "for his defense of science" ? No. He was a dangerous lunatic that actually managed to organize an armed force that successfully (for a time) tried to implement his view of a "morally correct" society by mass murder.