Was it Shakespeare? Was it Homer?
If you googled for the answer, you probably think Euripides. This is a classic example of something being repeated on the internet so much that people think it must be true. The answer isn't Euripides.
In its usual wording as above, it comes from Henry Wadsworth Longfellow. But he was rephrasing a saying that goes back more than 2,500 years. The earliest use I know of is the play Antigone, where Sophocles quotes a version, which I've stolen from the Perseus translation:
For with wisdom did someone once reveal the maxim, now famous,Sophocles then adds:
that evil at one time or another seems good,
to him whose mind a god leads to ruin.
But for the briefest moment such a man fares free of destruction.Which is a variant of, "Well it seemed like a good idea at the time!"
And as the text makes clear, by the time of classical Athens it was already considered an old saying. The origin must go back into prehistory. Which is rather cool really for such a subtle idea.