As BP and Transocean officials struggled to contain the oil gusher in the Gulf of Mexico, they discovered that the plumbing on the blowout preventer was connected improperly, a BP executive testified Wednesday.

"It would mean that the pipe rams could not be closed," said Harry Thierens, BP executive vice president for drilling and completions. "I was frankly astonished that this could have happened."

Thierens was testifying in Houston before a federal panel investigating the April 22 disaster.

Thierens said a plumbing line that was supposed to be connected to one of the rams meant to cut off a runaway well was actually connected to a test ram that would be of no use in containing the well.

"It would mean that test ram would close in an emergency, but it would not be capable of withstanding pressure from below," Thierens said.

Some time after the plumbing problem was discovered, technicians used a work-around method to try to activate the proper ram. That effort also failed to contain the well.

The blowout preventer is a stack of heavy equipment that sits on the bottom of the ocean and serves as the last line of defense against a gusher. The preventer on BP's Macondo well failed, leading to months of contamination in the gulf.

BP owned the well and directed the drilling operation. The rig and the blowout preventer were under contract from Transocean. The two companies have been trying to deflect responsibility to each other.

A log kept by Thierens recorded his bewilderment that the blowout preventer had been modified and noted that he had immediately met with Transocean engineer William Stringfellow Jr. and others working to choke the well:

"When I learned this news I lost all faith in this BOP stack plumbing. Billy Stringfellow, clearly emotional told me 'this stack is plumbed wrong'," Thierens wrote.

The plumbing issue affected efforts to jump-start the preventer using underwater robots but not the initial effort to trigger the preventer from the burning rig.

Thierens was asked about the chain of command on the Deepwater Horizon oil rig, which witnesses and members of the federal panel have described as confused, with authority divided among three leaders. Thierens said that he didn't know the chain of command.