TUCSON, Arizona (Reuters) - A congresswoman was shot in the head and seriously wounded and at least five other people were killed by a man who opened fire at a meeting the politician was holding in Tucson on Saturday, officials said.

Gabrielle Giffords, a 40-year-old Democrat in her third term in the House of Representatives, was airlifted to a hospital in Tucson after being shot at close range outside a grocery store in the Arizona city.

Giffords underwent surgery and one of the doctors who treated her said he was very optimistic about her recovery.

President Barack Obama said five people had been killed in the attack, including federal judge John Roll and a 9-year-old girl. Obama said Giffords was battling for her life.

“We don’t yet know what provoked this unspeakable act,” Obama told reporters at the White House after dispatching FBI Director Robert Mueller to Arizona to oversee the investigation.

A federal law enforcement official identified the suspected gunman as Jared Loughner, 22, of Tucson. The official said the suspect was tackled after the shooting and was in custody.

Rick Kastigar, an official from the Pima County Sheriff’s Department, told CNN that six people were killed among the 18 people shot.

Gun violence is common in the United States, which is periodically rocked by mass shootings, but political shootings are rare, although not unheard of.

The shooting followed contentious congressional elections in November marked by heated rhetoric over issues such as the Democratic party-led drive to overhaul the healthcare system and immigration reform.

A window in Giffords’ office was smashed last March, after Congress passed the healthcare overhaul that had been opposed by Republicans.

“The rhetoric is really heated. Not just the calls but the e-mails, the slurs,” Giffords told MSNBC at the time.

In several YouTube videos, a person who posted under the name Jared Lee Loughner criticizes the government and religion and calls for a new currency.

“The government is implying mind control and brainwash on the people by controlling grammar. No! I won’t pay debt with a currency that’s not backed by gold and silver! No! I won’t trust in God!”

OPTIMISTIC ABOUT RECOVERY

Doctors said Giffords was in a critical condition but they were optimistic about her recovery.

“The neurosurgeons have finished operating on her and I can tell you that in the current time period I am very optimistic about recovery... she was following commands,” Dr. Peter Rhee told a news conference at Tucson University Medical Center.

Nine other shooting victims were being treated for wounds at the hospital, Rhee said.

Slideshow ( 18 images )

Giffords was hosting a “Congress on Your Corner” event -- public gatherings to give her constituents a chance to talk directly with her -- when the gunman attacked from about 4 feet away, National Public Radio said.

The suspect used a pistol with an extended magazine and approached Giffords from behind, firing at least 20 shots at her and others in the crowd, television network MSNBC said, citing law enforcement officials and witnesses.

Giffords, whose district stretches from Tucson to the Mexican border, an area at the center of the debate on U.S. immigration, advocates a compromise policy of tough border security combined with a long-term path to citizenship for illegal immigrants.

She criticized Arizona’s tough anti-immigration law passed last year, saying it would do nothing to secure the border or stop drug smuggling and gun running. Her Tucson office was vandalized due to her opposition to the law.

Slideshow ( 18 images )

Regarded as a rising star in the Democratic Party, she narrowly defeated a conservative opponent and was one of the few Democrats to survive the Republican sweep in swing districts in the November elections.

A gun owner, Giffords differed with many Democrats on gun control and supported the Second Amendment to the Constitution on Americans’ right to bear arms.

Obama called the shooting a “senseless and terrible act of violence.”

The Washington Post said it was not the first time someone brought a gun to a Giffords event. A protester in August took a gun to a similar event in Douglas, Arizona. Police were alerted after he dropped the firearm, the newspaper said.

WARNING TO LAWMAKERS

House Speaker John Boehner, whose Republican Party won control of the House of Representatives in the November 2 elections, said in statement he was horrified by the attack on Giffords and members of her staff.

“An attack on one who serves is an attack on all who serve. Acts and threats of violence against public officials have no place in our society,” he said.

U.S. Capitol Police, charged with protecting U.S. lawmakers and the Capitol complex, said in a statement it had advised House lawmakers to “take reasonable and prudent precautions regarding their personal safety and security.”

The shooting could affect the immediate congressional agenda, a senior Republican lawmaker said.

The House is scheduled to vote next week on a repeal of Obama’s healthcare overhaul, which Giffords backed despite angry opposition from conservative activists in her district.

House Republican Leader Eric Cantor, who is in charge of the House floor schedule, suggested the timing of the healthcare vote might change.