“O Captain! my Captain! our fearful trip is done, The ship has weather’d every rack, the prize we sought is won, The port is near, the bells I hear, the people all exulting,”
Walt Whitman wrote this in Leaves of Grass. It appears in O Captain! My Captain!.
Where it appears
For the sweetest, wisest soul of all my days and lands—and this for his dear sake, Lilac and star and bird twined with the chant of my soul, There in the fragrant pines and the cedars dusk and dim. O CAPTAIN! MY CAPTAIN! O Captain! my Captain! our fearful trip is done, The ship has weather’d every rack, the prize we sought is won, The port is near, the bells I hear, the people all exulting, While follow eyes the steady keel, the vessel grim and daring; But O heart! heart! heart! O the bleeding drops of red, Where on the deck my Captain lies,
From the public-domain edition, read it free.