Media playback is unsupported on your device Media caption Gabrielle Giffords was the intended target, Sheriff Clarence Dupnik said

A US congresswoman has been shot in the head and six other people have been killed by a gunman in Arizona.

Democratic Representative Gabrielle Giffords, 40, was shot at close range during a public meeting in Tucson.

She is in a critical condition, but the doctor treating her said he was "very optimistic about her recove".

The dead included a nine-year-old girl and a federal judge. President Barack Obama said the shooting was a "tragedy for our entire country".

The Associated Press news agency reported that one of Ms Giffords' political aides was also killed in the shooting.

Mark Mardell's America It is an indication of the febrile, volatile nature of politics in America that, immediately the news broke, the internet was alive with anger Read Mark's thoughts in full

In addition to the six deaths, police said a total of 13 people - including Ms Giffords - had been shot and wounded in the attack.

A suspect named by US media as Arizona resident Jared Loughner, 22, was arrested after the incident.

Local police, who have not confirmed the suspect's name, said they were hunting a possible accomplice.

"[The suspect] has kind of a troubled past, and we're not convinced that he acted alone," said Pima County Sheriff Clarence Dupnik.

"There is some reason to believe that he came to this location with another individual."

Presidential tribute

The attacker struck as Ms Giffords held one of her regular open-invitation meetings - which she called "Congress on your corner" - with her constituents outside a supermarket in Tucson. Ms Giffords was initially reported to have been killed at the scene.

Media playback is unsupported on your device Media caption President Obama: "A tragedy for our entire country"

An eyewitness to the killings, Steven Rayle, told AP he had played dead to escape.

"I had passed by the table, the congresswoman was standing there talking to several people, I went to the side of the table... and I looked up and I saw a man shoot her in the head," said Mr Rayle.

"Then he began just spraying gunfire everywhere. At that point I ducked behind the concrete post.

"The whole thing unfolded in maybe 12 or 15 seconds. As he came around [the post], I lay on the ground and acted as if I were shot."

The gunman was reportedly overpowered by members of the crowd, before being taken away by police.

GABRIELLE GIFFORDS Represents Arizon's eighth district

First elected in 2006, re-elected to third term last November

Has focused on immigration, military issues, stem-cell research and energy

Grew up in Tucson, Arizona

Married to US astronaut Mark Kelly In pictures: Gabrielle Giffords

The dead judge was named by officials as John Roll, who had spent more than 40 years on the federal bench. It is not thought that he was deliberately targeted.

Mr Obama urged the nation to "come together, and support each other".

"I ask all Americans to join me and Michelle in keeping all the victims and their families, including Gabby, in our thoughts and prayers," he said.

He described Ms Giffords as a personal friend and an "extraordinary public servant".

Mr Obama has tasked FBI director Robert Mueller with overseeing the investigation.

'Rising star'

Ms Giffords, who represents the eighth district of Arizona in the House of Representatives, is married to space shuttle astronaut Mark Kelly.

US political assassinations 2008: Bill Gwatney, chairman of the Arkansas Democratic Party, shot in his office and later died

2003: New York City Councilman James Davis shot in the chest

1998: Tommy Burks, a Democratic state representative from Tennessee, shot in the face by a political opponent

1980: Russell Lloyd, Republican mayor of Evansville, Indiana and New York City Democratic Congressman Allard Lowenstein are assassinated

1978: Harvey Milk, a gay rights activist and San Francisco city supervisor, shot dead in his office. Mayor George Moscone killed moments earlier by the same shooter

She has served on several congressional committees, including those covering the armed services and foreign affairs, and is a member of the "blue dog" group of centrist Democrats.

Jeff Rogers, chairman of the local Democrats, told the BBC that Ms Giffords was "a rising star" in the Democrats with hopes of eventually winning the Arizona Senate seat.

She upset Arizona conservatives by supporting Mr Obama's healthcare reform bill last year.

Former Alaska Governor Sarah Palin, a conservative Republican, placed Ms Giffords on a list of politicians she wanted to remove from office in mid-term elections last November.

Ms Palin has issued a statement offering her condolences to the families of Ms Giffords and the other victims of the attack.

The House of Representatives majority leader Eric Cantor announced that all of next week's legislative debates would be postponed to allow politicians to "take whatever actions may be necessary in light of today's tragedy".