TEL NOF AIR BASE, Israel — Looking thin, weary and dazed, Israeli soldier Gilad Schalit emerged from more than five years in Hamas captivity today, surrounded by Hamas militants with black face masks and green headbands who handed him over to Egyptian mediators in an exchange for 1,000 Palestinian prisoners. Israeli military officials said Schalit showed signs of malnutrition.

More than 450 Palestinians were transferred from Israeli prisons to the West Bank and Gaza, where massive rallies to celebrate their freedom were held. In Gaza City, tens of thousands crammed into a sandy lot where a huge stage was set up, decorated with a mural depicting Schalit’s capture in a June 2006 raid on an army base near the Gaza border. Thousands hoisted green Hamas flags, and masses of people lined Gaza’s main highway to greet the arriving prisoners. The rest of the prisoners will be released in two months.

Speaking to Egyptian TV, Schalit said he felt good and was “very excited” to be going free. But the circumstances of his release, along with the awkward TV interview, raised questions about the conditions the 25-year-old had endured.

Schalit, who had not been seen in public since his capture, was whisked across Gaza’s border with Egypt early today, setting the swap into motion.

Wearing a black baseball hat and gray shirt, he was pulled out of a pickup truck and turned over to Egyptian mediators by a gang of top Hamas militants, some masked and some with their faces exposed. Among them was Ahmed Jabari, the shadowy head of Hamas’ militant wing, one of Israel’s most wanted militants.

Schalit, still escorted by Hamas gunmen, was then taken to a border crossing, where an Egyptian TV crew waited to interview him before he was finally sent into Israel.

Stumbling over his words, he spoke in the interview of missing his family and friends, said he feared he would remain in captivity “many more years” and worried that the deal might fall through after learning about it last week.

“Of course I missed my family. I missed friends, meeting people to talk to people, and not to sit all day, to do the same things,” he said.

Schalit appeared pale and gaunt, shifted in his seat, his breathing labored and seeming to mumble as he answered the questions. In one picture taken of the interview, a Hamas gunman with black face mask and green headband of the Hamas military brigade could be seen lurking in the background.

Israeli officials reacted angrily to the interview, saying it was inappropriate to force Schalit to answer questions in such difficult circumstances. But the interviewer, Shahira Amin, said he had not been coerced.