Flight controllers scrubbed the launch of the space shuttle Discovery less than two hours before its much-anticipated liftoff Wednesday because of a malfunctioning sensor that monitors the flow of liquid hydrogen in the external fuel tank.

The cancellation frustrated NASA and a legion of well-wishers, and raised questions about the space agency's ostensibly exhaustive efforts to upgrade the shuttle's performance and safety features in the 21/2 years since the Columbia disaster.

Engineers had encountered similar problems with "engine cutoff sensors" in another fuel tank during a test in April but decided to fly Wednesday with an "unexplained anomaly" even though they were unable to pinpoint the cause.

"We had a long conversation [in April] about what to do, so we changed out every cable connector, all the wiring and every electronic box," said Wayne Hale, deputy shuttle program manager. "We felt we had a good system."

Hale said engineers were trouble-shooting the malfunction on Kennedy Space Center's Launch Pad 39B and would decide Thursday what to do. But, he added, "we would not in any conceivable way be able to launch before Saturday."

The scrub at 1:33 p.m. Eastern time brought an unexpected denouement to a countdown that had progressed almost without flaw and amid increasing excitement as midday thunderstorms -- seemingly the only possible deal-breaker for the launch -- gave way to sunshine as the 3:51 p.m. liftoff approached.

Instead, mission commander Eileen Collins and the six other Discovery astronauts, strapped on their backs as the countdown ticked away, were abruptly told by launch director Mike Leinbach: "We are going to have to scrub this launch attempt."

The launch would have been the first since the Columbia disintegrated on reentry on Feb. 1, 2003, and was widely touted as the opening event in President Bush's "Vision for Space Exploration," which seeks to put humans back on the moon by 2020 and then send them eventually to Mars.

More than 1,250 newspeople arrived to witness the launch, and the parking lot at the media site was filled with 100 television trucks bristling with satellite dishes.

Visiting lawmakers, including House Majority Leader Tom DeLay (R-Tex.); Sen. Kay Bailey Hutchison (R-Tex.), chairman of the science and space subcommittee; and Sen. John F. Kerry (Mass.), last year's Democratic presidential nominee, offered condolences and encouragement.

"This wasn't a failure, this was a success," said House Science Committee Chairman Sherwood L. Boehlert (R-N.Y.). "The success was that they identified the problem before the launch, not afterwards -- that's not failure."

Former astronaut and senator John Glenn (D-Ohio), the closest thing NASA has to a living legend, agreed. But that did not make it any easier to take.

"Disappointed? Oh, yeah," Glenn said. "But it happens. I went on the 11th scheduled date my first time out." Glenn became the first American to orbit Earth with his 1962 flight.

At Space View Park in Titusville, Fla., spectators who had gathered to watch the launch began drifting away in disappointment when the announcement came. Jennifer and Nick Cox, who had driven almost three hours in heavy traffic from Tampa armed with folding chairs, sandwiches, drinks and a video camera, had hoped to make it the highlight of Jennifer's 32nd birthday celebration Wednesday.

Problems with the engine cutoff sensors first arose in April during a "tanking test" of Discovery's 154-foot external tank, which holds 1.6 million pounds of liquid oxygen and liquid hydrogen, fuel for the main engines during the shuttle's 81/2-minute dash into space. The sensors -- four for oxygen, four for hydrogen -- are safety devices that would trigger a main engine shutdown if the tank ran out of fuel prematurely. "You're feeding the big pumps, and you can do serious damage" if the engines do not shut down, Hale said.

Filling the tank is an exacting and hazardous three-hour exercise, as the pumping system and the tank itself must first be cooled until they are ready to accept liquids chilled to several hundred degrees below zero.

Two of the hydrogen sensors malfunctioned "intermittently" in the April test, but in a second test in May they performed normally. However, further tests on the "point sensor box," which routes the sensor signals to the orbiter's computers, showed anomalies.

Unable to figure out what was wrong, Hale said, engineers changed the box, rewired all the circuits and switched the connectors. They also swapped the external tank for a different one in a move that had nothing to do with the sensors.

There was no reason to do another full-scale tanking test before Discovery went to the launchpad, Hale said then.

"We did a real good test of the point sensor box to determine if there was something generic wrong with all of them," he said Wednesday. By changing out all the parts, "most likely we fixed this." He said NASA engineers discussed the decision right up until their last meeting Tuesday.

Tanking began at 7:11 a.m. Eastern time Wednesday and finished a little more than three hours later without incident. After that, there was little to do but load the astronauts and watch the thunderheads coming in from the Atlantic.

Still not confident about the sensors, however, engineers had added a simulation to the countdown to test them. A sensor reads "wet" if there is fuel in the external tank and "dry" if it is empty. Orbital project manager Steve M. Poulos Jr. explained that the simulation began by giving the sensors an artificial "dry" signal. Three of the hydrogen sensors soon snapped back to "wet." The other one did not.

Five minutes later, Leinbach scrubbed the launch. Poulos said it may be possible to reschedule for Saturday, especially if the problem is simply an open circuit that can be easily repaired. But shuttle program manager Bill Parsons made clear that the date could change.

The launch window lasts until the end of the month, but NASA could lose a lot of that time, especially if it decides to move Discovery off the launchpad for repairs. The next launch window will open in early September.

Staff writer Sylvia Moreno contributed to this report.

Discovery's astronauts, who had been strapped on their backs in the shuttle when they found out about the cancellation, return from the launchpad.

Bob and Jackie Fain of Wellston, Ohio, who had awoken at 3:30 a.m. to secure a good viewing position for Discovery's launch, leave Jetty Park across from the Kennedy Space Center in Cape Canaveral, Fla., after learning of the scrub.