The shootings raised questions about potential political motives, and Sheriff Dupnik blamed the toxic political environment in Arizona. There were immediate national reverberations as Democrats denounced the fierce partisan atmosphere in Ms. Gifford’s district and top Republicans quickly condemned the violence.

Mark Kimble, an aide to Ms. Giffords, said the shooting occurred about 10 a.m. in a small area between an American flag and an Arizona flag. He said that he went into the store for coffee, and that as he came out the gunman started firing.

Ms. Giffords had been talking to a couple about Medicare and reimbursements, and Judge Roll had just walked up to her and shouted “Hi,” when the gunman, wearing sunglasses and perhaps a hood of some sort, approached and shot the judge, Mr. Kimble said. “Everyone hit the ground,” he said. “It was so shocking.”

The United States Capitol Police, which is investigating the attack, cautioned lawmakers “to take reasonable and prudent precautions regarding their personal security.”

Because of the shootings, House Republicans postponed all legislation to be considered on the floor this week, including a vote to repeal the health care overhaul. The House majority leader, Representative Eric Cantor, Republican of Virginia, said lawmakers needed to “take whatever actions may be necessary in light of today’s tragedy.”

Speaking of Ms. Giffords’s condition, Dr. Rhee said at a news conference, “I can tell you at this time, I am very optimistic about her recovery.” He added, “We cannot tell what kind of recovery, but I’m as optimistic as it can get in this kind of situation.”

Ms. Giffords remained unconscious on Saturday night, said her spokesman, C. J. Karamargin.

Several aides to Ms. Giffords were wounded, and her director of community outreach, Gabriel Zimmerman, 30, was among those killed. The girl who died was identified as Christina Green, a third grader. The others killed were Dorothy Morris, 76; Dorwan Stoddard, 76; and Phyllis Schneck, 79.

Ms. Giffords, who represents the Eighth District, in the southeastern corner of Arizona, has been an outspoken critic of the state’s tough immigration law, which is focused on identifying, prosecuting and deporting illegal immigrants, and she had come under criticism for her vote in favor of the health care law.

Image Jared Lee Loughner, 22, whom the police identified as the main suspect in the shooting, at the 2010 Tucson Festival of Books in March. Credit... Mamta Popat/Arizona Daily Star, via Associated Press

Friends said she had received threats over the years. Judge Roll had been involved in immigration cases and had received death threats.

The police said Ms. Giffords’s district office was evacuated late Saturday after a suspicious package was found. Officers later cleared the scene.

Ms. Giffords, widely known as Gabby, had been speaking to constituents in a store alcove under a large white banner bearing her name when a man surged forward and began firing. He tried to escape but was tackled by a bystander and taken into custody by the police. The event, called “Congress on Your Corner,” was outside a Safeway supermarket northwest of Tucson and was the first opportunity for constituents to meet with Ms. Giffords since she was sworn in for a third term on Wednesday.

Ms. Giffords was part of the Democratic class of 2006 that swept Democrats into the majority in the House. She narrowly won re-election in November, while many fellow Democrats were toppled and the House turned to Republican control.

“I saw the congresswoman talking to two people, and then this man suddenly came up and shot her in the head and then shot other people,” said Dr. Steven Rayle, a witness to the shootings. “I think it was a semiautomatic, and he must have got off 20 rounds.”

Dr. Rayle said that Ms. Giffords slumped to the ground and that staff members immediately rushed to her aid. “A staffer had his arm around her, and she was leaning against the window of the Safeway,” the doctor said. “He had a jacket or towel on her head.”

At least one of the other shooting victims helped Ms. Giffords, witnesses said.

Television broadcasts showed a chaotic scene outside a normally tranquil suburban shopping spot as emergency workers rushed to carry the wounded away in stretchers. Some of the victims were taken from the site by helicopter, three of which had arrived.

Law enforcement officials said that the congresswoman had received numerous threats.

Congressional leaders of both parties issued statements throughout the day expressing outrage at the shooting as well as concern and prayers for Ms. Giffords and her family.