* Obama: US wants to cooperate with Africa on food security
* President departs Senegal for South Africa
* White House defers to Mandela family on possible visit
* S.Africa trip to be tribute to ill anti-apartheid leader (Adds Obama quotes, end of visit in Senegal)
By Jeff Mason and Mark Felsenthal
DAKAR, June 28 (Reuters) - President Barack Obama, wrapping up the first leg of an African tour, said on Friday Washington had a "moral imperative" to help the world's poorest continent feed itself and he then left for South Africa hoping to see ailing Nelson Mandela.
White House officials hope Obama's three-nation tour of Africa - his first substantial visit to the continent since taking office in 2009 - will compensate for what some view as years of neglect by America's first black president.
Before departing Senegal after a two-day stay, Obama met farmers and local entrepreneurs to discuss new technologies helping to raise agricultural output in West Africa, one of the world's most under-developed and drought-prone regions.
Standing in front of the agricultural displays at an event hosted by "Feed the Future", the U.S. government's global hunger initiative, Obama said his administration was making food security a top priority of its development agenda.
"This is a moral imperative. I believe that Africa is rising and wants to partner with us: not be dependent but be self sufficient," he told reporters. "Far too many Africans endure the daily injustice of poverty and chronic hunger.
"When people ask what's happening to their taxpayer dollars in foreign aid, I want people to know this money's not being wasted. It's helping feed families."
But the health of Mandela, the 94-year-old former South African president and anti-apartheid hero clinging to life in a Pretoria hospital, dominated Obama's day even before he arrived in Johannesburg.
Asked on Thursday whether Obama would be able to pay Mandela a visit, the White House said that was up to the family.
"We are going to completely defer to the wishes of the Mandela family and work with the South African government as relates to our visit," deputy national security adviser Ben Rhodes told reporters in Senegal.
South African President Jacob Zuma said Mandela's condition improved over Wednesday night but he remains in a critical state.
Some 200 trade unionists, student activists and Communist Party members protesting against American foreign policy gathered on Friday a few blocks from the hospital where Mandela is being treated for a lung infection.
MANDELA A "PERSONAL HERO"
Obama sees Mandela, also known as Madiba, as a hero. Whether they are able to meet or not, officials said his trip would serve largely as a tribute to the anti-apartheid leader.
"I've had the privilege of meeting Madiba and speaking to him. And he's a personal hero, but I don't think I'm unique in that regard," Obama said on Thursday. "If and when he passes from this place, one thing I think we'll all know is that his legacy is one that will linger on throughout the ages."
Like Mandela, Obama has received the Nobel Peace Prize and both men were the first black presidents of their nations.
Air Force One departed Senegal's coastal capital Dakar just before 1100 GMT (0700 AM ET) and was due to arrive in South Africa around eight hours later. On Friday evening, Obama has no public events scheduled and could go to the hospital then.
He is scheduled to visit Robben Island, where Mandela spent years in prison under South Africa's former white minority regime, later during his trip. Obama's last stop on his tour will be Tanzania in East Africa.
Obama only previous visit to the continent was a one-day stopover in Ghana at the beginning of his first term.
Food security, along with anti-corruption measures and trade opportunities for U.S. companies, are topics the White House wants to highlight on Obama's eight-day tour.
While acknowledging that Obama has not spent as much time in Africa as people hoped, the administration is eager to highlight what it has done, in part to end unflattering comparisons to accomplishments of predecessors George W. Bush and Bill Clinton.
Food security and public aid are two of the issues the Obama team believes are success stories. USAID head Raj Shah told reporters that Africa had seen a steady increase in resources under Obama's administration despite a tough budget environment. (Writing by Daniel Flynn and Jeff Mason; editing by Mark Heinrich)