An American service member was killed and three others were wounded Thursday afternoon when a suicide bomber rammed a car packed with explosives into a heavily armored military vehicle just outside a base where U.S. Defense Secretary Leon E. Panetta had been visiting troops earlier in the day.

The attack outside Kandahar Airfield, a heavily-guarded base in Kandahar province, underscored the tenuous security in the country’s south, the Taliban’s heartland, as the U.S. military footprint continues to thin out. Two Afghan civilians were killed and several were wounded by the blast, local officials said.

The bombing happened about 5 p.m., just a few hours after Panetta had been at the base thanking troops for their service during a wind-chilled outdoor ceremony. It was the second major security incident this year to cast a pall on a Panetta visit to Afghanistan. When the secretary was last here, in May, a suspected insurgent rammed a stolen vehicle into an airfield shortly after Panetta landed and tried to attack the visiting delegation.

After returning to Kabul on Thursday, Panetta met with Afghan President Hamid Karzai to discuss the size and type of U.S. military force that might remain in place after the end of the American combat mission in Afghanistan in December 2014.

“We now have an opportunity to make these gains lasting,” the secretary said during a joint news conference at the presidential palace. “We must be bold enough to seize the opportunity.”

Panetta and U.S. commanders have struck an upbeat tone about the progress of the war, saying that American forces are increasingly stepping into support roles and leaving the front lines to Afghan troops. But Panetta said the conflict remains tough.

“These are long-term challenges,” he said. “This is a war we’re engaged in.”

Panetta said the Obama administration will host Karzai in Washington the week of Jan. 7 to discuss final details of a security agreement that could spell out the terms of continued U.S. military presence here beyond 2014. The two leaders declined to discuss the troop levels under consideration.

Kevin Sieff in Kabul contributed to this report.