In February 2008, he stepped down as president, ceding power to his brother, Raul, and he last appeared on state television in June that year.
In Sunday's television broadcast he appeared in good health, telling the students that he was worried about the future of the planet, under threat from global warming.
"Even the Pentagon has become involved," Castro said.
"It has included the climate among things that threaten the security of the United States."
The students presented Castro with a T-shirt and sang: "We love you, Fidel. We love you."
Castro, wearing a blue track suit, told the students that Cuba stood by the Venezuelan government of President Hugo Chavez, a close friend and ally of Castro.
Meeting with Correa
The footage followed a front-page photograph of Castro meeting Rafael Correa, the Ecuadorean president, published in the official Juventud Rebelde newspaper.
A brief official note said Castro and Correa spoke for a number of hours on Friday about recent developments in their respective countries, Latin America and the world.
As Cubans gathered at kiosks on Sunday morning to pick up the paper, word spread that Fidel's photo had appeared.
"I'm waiting for the paper to see him because it's been a long time since a photo was published and I want to see how he is," said Arturo Martinez, one of those waiting for the paper to arrive a few blocks from Communist Party and government headquarters.