DUBLIN, Virginia — More than 20,000 gallons of lube oil spilled after a freight train was rear-ended by another train traveling in the same direction Tuesday in western Virginia, causing 18 cars and a locomotive to derail, Norfolk Southern said.

The oil, which is commonly used in machinery, spilled from one of the derailed rail cars. Scrap metal spilled from another car. The other cars that went off the tracks were empty, Norfolk Southern spokeswoman Susan Terpay said Wednesday in an email.

Two crew members were treated for injuries at a hospital and released, Terpay said.

The westbound Norfolk Southern train was struck from behind by a second Norfolk Southern train around 4 p.m. Tuesday near the small western Virginia town of Dublin. Terpay said eight rear cars on the first train and 10 cars on the second train, along with the locomotive, derailed.

Norfolk Southern initially had reported that five empty cars and the locomotive derailed.

Terpay said the spilled oil has been contained at the site and no waterways have been affected. The railroad and environmental contractors are working to clean up the site.

She said the cause of the crash and derailment is under investigation.

Dozens of emergency officials responded to the scene, The Roanoke Times (http://bit.ly/1dZf8bC) reported.

The train cars landed in the backyard of Kenny Trail, who was watching TV when he heard the noise, the newspaper reported. The train crushed his electric scooter, and he was immediately evacuated.

Another resident, Teresa Frank, heard the trains collide as she was picking green beans in her father's backyard.

"It was horribly loud, and I took off running back to the house," Frank told the newspaper. "I didn't know what it was, but we started seeing emergency cars show up."

Frank said the daily sounds of trains have become background noise for many residents.

"You hear all kinds of banging ... on the tracks," she said. "But this was super loud, so I thought something was wrong."