Mark Twain wrote it. It heads chapter XII of his novel Pudd’nhead Wilson (1894) as one of the sayings from “Pudd’nhead Wilson’s Calendar”, and it is one of the few famous Twain lines that can be found word for word in his own book. It continues with a comic paragraph about the flea.
What it means
Being brave does not mean feeling no fear; it means feeling it and not letting it decide what you do. Someone who is never afraid is not courageous, only unaware.
Where it comes from
Each chapter of Pudd’nhead Wilson opens with an entry from the fictional almanac of its hero, the lawyer David “Pudd’nhead” Wilson. Chapter XII, “The Shame of Judge Driscoll”, opens with this one. As printed, the first sentence uses double hyphens: “Courage is resistance to fear, mastery of fear--not absence of fear.”
The entry does not stop there. It goes on: “Except a creature be part coward it is not a compliment to say it is brave; it is merely a loose misapplication of the word. Consider the flea!--incomparably the bravest of all the creatures of God, if ignorance of fear were courage.” It ends by suggesting the flea be put at the head of the procession of heroes. The serious sentence is the set-up for the joke, which is also the argument: an animal that knows no fear is not brave.