Markets turn cautious, reversing an early gain to end lower