(Updates death toll, details of flood damage)
HOUSTON, Aug 29 (Reuters) - President Donald Trump visited Texas on Tuesday to survey damage from the first major natural disaster to test his leadership in a crisis, as record rainfall from Tropical Storm Harvey lashed Houston and tens of thousands of people fled deluged homes.
The storm turning slowly in the Gulf of Mexico has brought catastrophic flooding to Texas, killing at least 13 people and paralyzing Houston, America's fourth most populous city.
With damage expected to run well into the tens of billions of dollars, it will rank among the costliest U.S. natural disasters.
City officials readied temporary housing for about 19,000 people, with thousands more expected to flee as flooding entered its fourth day and space ran out in cramped shelters.
By Tuesday morning, nearly 50,000 homes had suffered flood damage, Texas officials said, and the tally will climb.
Houston Mayor Sylvester Turner announced curfew from 12 a.m. to 5 a.m. amid reports of looting, armed robberies and people impersonating police officers.
Nearly a third of Harris County, with a population of 4.6 million, was under water, an area 15 times the size of Manhattan, the Houston Chronicle newspaper said.
Harvey has affected nearly a fifth of U.S. refining capacity, triggering worries about lack of gasoline and sending gasoline futures to a two-year high.
Houston residents glimpsed patchy sunlight on Tuesday afternoon for the first time in days, but forecasters warned 6 to 12 inches (15 to 30 cm) of rain was on its way through Thursday, badly straining the dams and drainage systems that protect a low-lying metropolitan area whose economy is about as large as Argentina's.
Harris County officials warned residents to evacuate as they released water from overflowing reservoirs to alleviate pressure on two dams, adding to flooding along the Buffalo Bayou waterway that runs through Houston.
Residents within 1.5 miles (2.4 km) of a chemical plant in Crosby were also ordered to evacuate, due to the growing risk of an explosion and subsequent leak.
$50 BILLION IN DAMAGE
Trump, speaking in Corpus Christi near where Harvey first came ashore last week as the most powerful hurricane to strike Texas in more than 50 years, called for an exemplary relief effort.
"This was of epic proportion. Nobody's ever seen anything like this," Trump said of Tropical Storm Harvey, as he met state and federal officials for a briefing.
The president said he was pleased with the response, but it was too soon for a victory lap.
"We won't say congratulations," he said. "We don't want to do that...We'll congratulate each other when it's all finished."
Harvey has drawn comparisons with Hurricane Katrina, which devastated New Orleans 12 years ago, killing 1,800 people and causing an estimated $108 billion in damage.
Former President George W. Bush was criticized for his administration's handling of the response to that disaster, causing a heavy toll in public support, and Trump clearly was aiming to avoid a similar reaction.
Damage from Harvey could cost Houston up to $50 billion in lost economic activity and property damage, the Houston Chronicle said, citing an estimate from the Greater Houston Partnership and Moodys Analytics.
The 13 confirmed deaths included a family of six and Houston Police Sergeant Steve Perez, a 34-year force veteran who drowned while attempting to drive to work on Sunday, Police Chief Art Acevedo told reporters.
"We have work to do," the 60-year-old Perez had said to his family, dismissing their appeals to him to stay home because of the flooding, Acevedo told a news conference.
In Beaumont, northeast of Houston, raging floods swept away a woman clutching her baby daughter, who was saved although her mother died, police said.
U.S. Coast Guard air units and boats have rescued more than 4,000 people. Citizen volunteers used boats to bring to safety hundreds more.
The water line is higher than the roofs of some houses, said Commander Jim Spitler, commanding officer of Coast Guard Air Station Houston. He urged people stuck on roofs after dark to shine a flashlight or a cell phone light into the night sky, to attract the attention of air crews.
A record 51.88 inches (131.78 cm) of rain has fallen in Texas due to Harvey, a record for any storm in the continental United States, the National Hurricane Center said on Tuesday.
That breaks a 1978 record of 48 inches (122 cm) during tropical storm Amelia in Medina, Texas, it added. In 1950, before Hawaii became a U.S. state, tropical cyclone Hiki dumped 52 inches (132 cm) of rain on the island of Kauai.
Houston's George R. Brown Convention Center houses about 9,000 evacuees, and city officials on Tuesday opened the Toyota Center arena and parts of the NRG football stadium complex for others.
Other shelters were set up in Dallas, about 250 miles (400 km) to the northwest, for about 8,000 people, and Austin, 160 miles (258 km) west, to take in 7,000 people. The Red Cross said it had 34,000 cots in the region and enough food.
The slow-moving storm's center was in the Gulf of Mexico about 70 miles (150 km) southeast of downtown Houston by Tuesday evening and Harvey was expected to move inland again early Wednesday near the Louisiana-Texas border, the U.S. National Hurricane Center said.
(Additional reporting by Gary McWilliams, Ernest Scheyder, Erwin Seba, Ruthy Munoz and Peter Henderson in Houston; Andy Sullivan in Rockport, Texas; Jon Herskovitz in Austin; Steve Holland in Corpus Christi, Texas; Bernie Woodall in Fort Lauderdale, Florida, David Gaffen in New York and Alex Dobuzinskis and Dan Whitcomb in Los Angeles; Writing by Scott Malone and Dan Whitcomb; Editing by Bill Trott and Clarence Fernandez)