CEDAR RAPIDS, Iowa — Miles of hastily erected barriers were remarkably effective in preventing the surging Cedar River from pouring into Cedar Rapids, Iowa’s second-largest city, but officials said the sand-filled containers wouldn’t work in every flooding situation.

Officials spent roughly $5 million to create a nearly 10-mile line of Hesco barriers along the river in days, keeping the river out of the city of 130,000 even in spots that were as much as 4 feet below the water level. The danger isn’t over yet, but the Cedar River crested at nearly 22 feet Tuesday and is expected to fall below flood stage by this weekend.

The barriers have been used to prevent flooding for years in spots from New York City to Los Angeles, but rarely have they been as high-profile or effective as they were shown to be in Cedar Rapids, where a 2008 flood inundated 10 square miles of the city and caused billions of dollars in damage.

Although the barriers worked well, Cedar Rapids leaders still support construction of a $500 million system of flood barriers. The city is lobbying for $73 million in federal money for the permanent flood controls after securing a major state commitment.

Mayor Ron Corbett said that while the city evened the score this year with the Cedar River after getting “skunked” in 2008, there will no doubt be a rematch in coming years.

“That’s why we need to continue to work on flood mitigation and flood protection,” he said. “And flood protection means building permanent walls and levees so we don’t have to go through this again.”

As well as the barriers worked, officials warned the city may not always have enough time to build the makeshift walls, which took around-the-clock work by an army of contractors. Unlike flooding in many parts of the country, officials knew the Cedar River flooding was coming days in advance because of intense rainstorms last week more than 100 miles upstream in northern Iowa.

Officials said the temporary structures also might not work against a flood the size of the one that destroyed large swaths of the city in 2008. During that flood, the river was 9 feet higher than this year’s crest.

And they say the temporary system is more susceptible to breeches that could send water dangerously gushing into neighborhoods and downtown.

“The investment in the Hesco barriers has allowed us to protect our city, but long term we do need permanent flood protection,” City Manager Jeff Pomeranz said.

Still, city leaders said they were thankful for the barriers, which have been used increasingly in the Midwest after becoming ubiquitous at overseas military bases as protection against bomb blasts.

The barriers were invented by British entrepreneur James Heselden, a former coal miner who used them to stop erosion and flooding on his property. After his invention received media attention, the United Kingdom’s military realized the barriers could be used to replace sandbags that protected soldiers from blasts in Bosnia, said Aaron Ackley, Hesco’s director of emergency response.

The U.S. military came to the same conclusion and began using the barriers extensively in Iraq and Afghanistan, eventually installing more than 30,000 miles of the containers, said Ackley, who first saw the barriers when he served with the U.S. Army in Bosnia.

In Cedar Rapids, once the river level drops, crews will face another big task: dismantling the barriers, determining which can be reused, and cleaning up tons of sand.

“The system went up in two days, but it’s going to take longer than that to disassemble the system and move the material out,” Pomeranz said.