Several cars were overturned but no injuries were reported.
The District of Columbia Fire Department said it had not ordered evacuations near the site of the accident, about three miles (5 km) from the White House.
Sodium hydroxide, used to produce household products including paper, soap and detergent, was leaking from one car, CSX Corp said in a statement.
Earlier, the fire department said three cars were leaking an unidentified substance or substances but there was no fire. Fire department photographs showed several cars lying on their sides by the tracks on the main train route into the city, including tank cars, bulk material cars and box cars.
The accident forced the closure of the Rhode Island Metro Station and Rhode Island Avenue, it said.
The train, with three locomotives and a total of 175 cars, most carrying mixed freight or riding empty, was traveling from Cumberland, Maryland, to Hamlet, North Carolina.
The Washington Metropolitan Area Transit Authority (Metro) could not immediately be reached for comment.
According to the U.S. Centers for Disease Control and Prevention website, sodium hydroxide is a caustic soda. It is a colorless to white, odorless and solid at room temperature, usually stored as flakes, beads or in granular form.