The Dow ekes out a gain after surrendering 300 points in the final hour of trading