Barack Obama offered a poignant glimpse into his African heritage and went on the offensive against female genital mutilation and other “bad traditions” that treat women as second-class citizens in a speech in Nairobi.

The US president addressed 5,000 Kenyans in the country’s capital on Sunday, in the centrepiece event of his first visit to his father’s homeland since he was elected.

“I am proud to be the first American president to come to Kenya and of course I’m the first Kenyan-American to be president of the United States, ” he said, prompting a cheer that almost blew the lid off a sports arena bedecked in US and Kenyan flags.

Mr Obama was introduced to the rapturous crowd by his half-sister, Auma, who looked after him on his first trip to the east African country in 1987. “The first time I came to Kenya things were a little different,” he said. “I arrived at Kenyatta airport, the airline had lost my bags. That doesn’t happen on Air Force One. They always have my luggage close to me.”

Auma had picked him up in an old VW Beetle that broke down four or five times. Mr Obama added: “I slept on a cot in her apartment. Instead of eating at fancy banquets with the president we were drinking tea and eating ugali [a maize-flour dish]. So there wasn’t a lot of luxury. Sometimes the lights would go out.

“But you know, there was something more important than luxury on that first trip and that was a sense of being recognised, being seen.”

Mr Obama had left university a few years earlier, worked as a community organiser in deprived areas of Chicago and was poised for law school. “I was American, unfamiliar with my father, his birthplace, really disconnected from half of my heritage. And at that airport, as I was trying to find my luggage, there was a woman there who worked for the airlines and she was helping fill out the forms.

“She saw my name and she looked up and she asked if I was related to my father, whom she had known. That was the first time my name meant something.”

Mr Obama told how he went on to meet various family members during his stay in Kenya and searched for details about his father, whom he had only met once when he was 10, and other ancestors. “I learned things about their lives that I could never have learned from books. In many ways their lives offered snapshots of Kenya’s history, but they also told us something about the future.”

His grandfather had been a cook for the British during the colonial era. “As I went through some of his belongings when I went upcountry, I found the passport he had had to carry as a domestic servant. It listed his age, his height, his tribe, it listed the number of teeth he had missing. And he was referred to as a ‘boy’, though he was a grown man, in that passport.”

Mr Obama’s father had served in Burma for the King’s African Rifles during the second World War. On his return, he endured detention because he was linked to a group that opposed British rule. “Eventually he was released and forged a home for himself and his family and he earned the respect of his village,” Mr Obama continued.

“He lived a life of dignity although he had a well-earned reputation for being so strict that everybody was scared of him and he became estranged from part of his family.”

Turning to Barack Obama snr, the president said: “My father came of age as Kenyans were pursuing independence. He was proud to be a part of that liberation generation. Next to my grandfather’s papers I found letters that he had written to 30 American universities asking for a chance to pursue his dream to get a scholarship.

“And ultimately one university gave him that chance, the University of Hawaii. He would go on to get an education and then return home. First he found success as an economist, worked with government, but ultimately he found disappointment in part because he couldn’t reconcile the ideas that he had for his young country with the hard realities that confronted him.

“I think sometimes about what these stories tell us, what the history and past tell us about the future. They show us the enormous barriers to progress that so many Kenyans faced just one or two generations ago. This is a young country.”

In characteristic fashion, Mr Obama wove together the history of Kenya, which became independent a few years after he was born, with his own story. “When it comes to the people of Kenya, particularly the youth, I believe there is no limit to what you can achieve. A young, ambitious Kenyan today should not have to do what my grandfather did and serve a foreign master. You don’t need to do what my father did and leave your home to get a good education and access to opportunity. Because of Kenya’s progress, because of your potential, you can build your future right here, right now.”

The audience erupted in applause. Outside, people lined streets in the hope of glimpsing the presidential convoy. Later in the speech, Mr Obama challenged Kenya, and Africa, on women’s rights, giving short shrift to those who hide behind arguments defending tradition and culture against values they say are imposed by the west.

“Every country and every culture has traditions that are unique and help make that country what it is, but just because something is part of your past doesn’t make it right, it doesn’t mean it defines your future,” he said, citing the recent debate in the US over the Confederate flag as an example.

He continued: “Around the world there is a tradition of oppressing women and treating them differently and not giving them the same opportunities, and husbands beating their wives, and children not being sent to school. Those are traditions. Treating women and girls as second-class citizens. Those are bad traditions: they need to change.”

The statement gained thunderous applause but Mr Obama was not finished: “Treating women as second-class citizens is a bad tradition: it holds you back. There’s no excuse for sexual assault or domestic violence, there’s no reason that young girls should suffer genital mutilation, there’s no place in a civilised society for the early or forced marriage of children. These traditions may go back centuries; they have no place in the 21st century. They are issues of right or wrong in any culture.

“But they are also issues of success and failure. Any nation that fails to educate its girls or employ its women and allow them to maximise their potential is doomed to fall behind the global economy. We’re in a sports centre: imagine if you have a team and don’t let half of the team play. That’s stupid. That makes no sense.” Guardian service