'Who is Barack Obama?" In the last, desperate weeks, that question became the rallying cry of John McCain and Sarah Palin, as they sought to persuade Americans that they knew too little about the man who, in the early hours of yesterday morning, was elected the 44th president of the United States. It was a rhetorical question, but it sometimes brought swift and harsh answers. "Who is the real Barack Obama?" McCain asked at a rally in Albuquerque last month. "A terrorist!" shouted at least one man in the crowd.

But that was only the crudest response. In the 21 months after Obama first launched what he always called his "improbable" bid for the White House, his opponents had sought to fill in the blank of his identity with a series of bogeymen. Obama was a Muslim and a Marxist. He was a conviction liberal and a believe-in-nothing celebrity. He was an ivory-tower professor and a crooked Chicago pol. He was an elite Ivy Leaguer and the product of a madrasa. He was an East Coast snob and an exotic quasi-foreigner. By the end, the McCain campaign and its allies, seeking to hurl every pot and pan in the kitchen sink at Obama, claimed all those things about the Democrat — often at the same time.

September 1 2008: Delegate Kelly Williams wears a hat showing his dislike for Barack Obama in St Paul. Photograph: Jae C Hong/AP

The notion that there was something mysterious or alien about Obama had been running all year. Mark Penn, one-time chief strategist to Hillary Clinton in her presidential bid, suggested his boss pose as the "American" candidate: "All of these articles about his boyhood in Indonesia and his life in Hawaii are geared towards showing his background is diverse, multicultural and putting that in a new light. Save it for 2050. It also exposes a strong weakness for him — his roots to basic American values and culture are at best limited. I cannot imagine America electing a president during a time of war who is not at his centre fundamentally American in his thinking and in his values."

That advice was later taken up with zeal by the Republicans. Last month Palin told a rally in Clearwater, Florida: "This is not a man who sees America the way you and I see America."

On one level this was simply a form of racial code, a way of nudging white voters to see that the first African-American nominee of a major party was not "one of us". But that is not the whole picture.

September 21 2008: Barack Obama speaks during a rally in Charlotte, North Carolina. Photograph: Chris Keane/Reuters

For the truth is that America's next president does indeed have a biography that is worlds apart — and, yes, more exotic — than the rest of his fellow citizens. It is rooted in the mud-hutted villages of Kenya and the flat cornfields of Kansas. It jumps from the endless summers of Hawaii to the ferment of 1960s Indonesia, from the gilded seminar rooms of Harvard to the broken streets of Chicago's South Side — and all that before Obama had turned 22 years old.

It is a strange and confusing enough tale that Obama himself had to work hard to untangle it, eventually shaping it into a coherent narrative in the lyrical, moving memoir authored when he was just 33 and now an international bestseller: Dreams from My Father. That book, and its successor, The Audacity of Hope, mean that Obama's story is hardly a mystery. He has laid its details bare. What's more, the narrative of his own life has lain at the heart of his political message.

He has offered his "improbable journey" as testament to the enduring power of the American dream: the belief that, in the United States, truly anyone can make it. As he put it in the speech that launched him into the political stratosphere, the keynote address to the Democratic convention of 2004, "in no other country on earth is my story even possible".

June 1 2008: Barack Obama addresses a rally in Mitchell, South Dakota. Photograph: Chip Somodevilla/Getty Images

But he has also suggested that his own hybridity — the child of a white mother and a black father — embodies the mixed nation that America is destined to become, that somehow his own reconciliation of the black and white within him is a harbinger of a wider reconciliation in America itself. That his roots across several continents make him the right man for a new and globalised age. That somehow his own past equips him for the future.

"I think that in a sense Barack is the personification of his own message for the country," David Axelrod, chief strategist for the Obama campaign, told the New York Times last year. "He is his own vision."

But the Obama biography translates into more than a campaign theme. Its details provide crucial clues as to how the new president thinks, what drives him and how he is likely to operate. To understand the man whose decisions will shape the world for at least the next four years, you need to know where he came from and the path he has travelled. It's long, taking the unlikeliest turns, but now we know where perhaps it was always leading — to the White House.

America's next president is the son of a man who once herded goats in a remote village in Africa. He is the grandson of a man who grew up among people who wore animal skins, in a village where no white man had ever set foot. That grandfather went on to become a cook for the British army and later a domestic servant, while his son finished secondary school by correspondence course, had four wives and eight children and died an early death, caused by drink and depression.

Portraits, including one of Barack Obama's father, hang in his family house in Kogelo, Kenya. Photograph: Peter Macdiarmid/Getty Images

The grandfather, Hussein Onyango Obama, is the source of the new president's middle name — the one that gave him so much trouble in the campaign. Though he is said to have been born in 1870, one of his three wives still lives. They call her "Mama Sarah" and she is now, aged 86, the step-grandmother of the most powerful man in the world.

You find her by taking the 90-minute drive north of Lake Victoria to the remote Kenyan village of Kogelo. At the end of the tarmac, a sign for the Senator Obama Secondary School points the way along a red dirt road. You find a small house, three rooms under a pale-blue corrugated iron roof. There is a water pump in the front garden and a huge mango tree, and it's here you stop and chat to Mama Sarah.

She's happy to talk, over the noise of the chickens that come running when she calls. She still works, rising at dawn on a typical day and heading barefoot into her vegetable garden, where she grows maize, sweet potatoes, beans and cassava. At nine, she makes breakfast, returning to the fields until noon.

She has a TV set now, a gift from a local airline executive, but she always used to follow the news on the radio in Swahili or Luo. And she has met her step-grandson only a few times. The first encounter came when he visited Kenya in the 1980s: they had no language in common but she can't forget his voice. So much like his father's, she says: "It made me think that his father had come back from the dead."

Her living room is decorated with family pictures, including a shot of Barack on one visit, carrying a sack of vegetables. She is proud of Barack, though she doesn't consider what he has achieved anything too special. When asked about the prospect of him becoming president, she described it as "just a job". But she plans to keep her promise to fly to Washington in January, to see her boy inaugurated. It won't be her first trip to the US. She saw Barack sworn in as a senator. She said that the US was "very interesting" — but "very cold".

Obama's father — also called Barack Hussein Obama — had once caused her pride too, but just as much consternation. He was bright, yet easily bored. He won a place in secondary school, but was expelled for behaving badly. He eventually finished his schooling by correspondence course , but not before he had a married a young woman called Kezia and had a son and daughter.

Once the course was complete, he met two American women in Nairobi who told him he should apply for a scholarship to study in the US. He wrote to dozens of US universities and one eventually replied: the University of Hawaii.

He had no idea where Hawaii was — but snapped up the offer of a place. Leaving his son and pregnant wife with Mama Sarah, he flew to Honolulu. And it was there he would meet a woman who was the product of the same urge he himself had felt — the urge to move westward and start over.

Stanley Ann Dunham was named after a father who had yearned for his first child to be a boy — and for much else. Dunham — the new president's other grandfather — had been born into small-town Depression-era Kansas, but he dreamed bigger. Wild in his youth, "dabbling in moonshine, cards and women", according to Obama's memoir, Dunham would not be contained by Wichita. He eloped with his sweetheart, Madelyn, enlisted after Pearl Harbour and fought in General Patton's army in France before hopping westward, always hoping for something better, from Texas to California and finally, when offered a job as a furniture salesman in America's newest state, to Hawaii.

These, then, were the backstories of the young African man and the 18-year-old girl who would meet on a Russian language course in Honolulu. They could not have been more different. He was a son of the Luo tribe who, when not in school, had herded his father's goats; she was the daughter of white Protestant prairie folk from the American heartland. And yet they fell in love. They married and in 1961 they had a child, who would also be called Barack Hussein Obama.

The marriage did not last. Obama Sr took up a scholarship in Harvard — alone — and eventually went back to Africa. He would go on to marry two other women, one of them American, and have a total of seven other children. He would return to Hawaii, to see his son and namesake, only once — a month-long visit when Obama Jr was 10 years old.

In Kenya, Obama Sr landed a senior post in the ministry of economic planning in Jomo Kenyatta's government. Tribalism hindered his progress: the Obamas are Luos, while Kikuyus had a tight grip on political power. But that was not the whole of it. According to those who knew him at the time, Obama Sr grew too fond of Scotch, loudly boasting of his brains and talent, before going home drunk every night.

Towards the end of his life Obama Sr had spent most of his savings. He became depressed, pushing most of his children away. But alcohol was to be his undoing. In 1982 the elder Barack Hussein Obama died in the last of a series of serious car accidents. He had not lived to see the remarkable fruit of his own improbable journey westward.

Barack Obama and his father, also named Barack Obama.. Photograph: Obama for America/AP

The second Barack Hussein Obama came into the world on August 4 1961 at the Kapi'olani Medical Center for Women and Children in Honolulu, Hawaii. By the time he was two years old his father had gone, his place in Ann Dunham's affections soon replaced by another foreign student at the University of Hawaii, an Indonesian named Lolo. Always restless, she decided to leave Honolulu so that she and her son, now barely six, could be with her new husband and start a new life in the east.

She arrived in Indonesia in a spirit of blissful "innocence" that her son would later marvel at with something less than admiration. Ann seemed only vaguely aware that the country was in turmoil, that just a few months earlier a coup attempt had been thwarted after which hundreds of thousands of people had been killed. Ever wide-eyed and hopeful, she believed individuals could shape their own future, regardless of whatever barriers history and geography might put in the way.

By all accounts the young Obama — Barry Soetoro as he was then, taking the name of his new stepfather — embraced his new surroundings with enthusiasm. When his mother wanted him to take a nap after school, he would sneak out to play in the muddy lanes of Jakarta, stopping for a swim with the local boys in the dirty pond known as the "empang".

Former classmates and teachers describe "Berry" — Barry with an Indonesian lilt — as inquisitive and fun-loving, even then displaying a precocious talent for leadership.

At St Franciskus Assisi Catholic school, the first he attended, his teacher Israella Pereira Darmawalla, 64, spotted it immediately. "He was a natural leader," she told the Guardian. "Before the children would come into class they would line up. Berry would inspect them and make sure they were straight, giving orders in Indonesian. No one told him to do it."

Those who remember him talk of a boy full of energy, building up a sweat as he hared around the playground, teasing the girls, attracting attention not only because of his dark skin and curly hair but because he was also left-handed — regarded as an extreme oddity in the ultra-conservative Indonesia of the 1960s.

"Berry really stood out," said Ati Kisyanto, 46, a classmate at the Basuki government elementary school. "He was much bigger than us. All the Indonesian kids were skinny and small. Berry was very chubby and had long, curly eyelashes. But from the start he fitted right in."

Sword fights with bamboo sticks and football were favourite pastimes in the lanes outside Obama's first home. There he and Lolo kept turtles, a monkey and even a baby crocodile — once deployed by the young Berry to scare off some local boys who were causing trouble. "They never came back," recalls neighbour, Ronny Amir, now 47.

Instruction came from his stepfather. Berry once sustained an egg-sized lump on his head, thanks to a stone hurled at him after he'd chased a boy who ran off with his ball. Lolo promptly produced a pair of boxing gloves, as he prepared to teach Berry that he had to be strong to survive in a tough world.

"Men take advantage of weakness in other men," Lolo told Berry, according to Dreams from My Father. "They're just like countries in that way. Better to be strong."

By the third year, Obama, now registered as a Muslim after his stepfather's religion — but educated in a non-religious school, not the madrasa that would later be claimed — gave another glimpse of his embryonic ambition. Darmawalla asked her pupils each to write a poem entitled My Dreams.

May 18 2008: Barack Obama speaks to a crowd at Waterfront Park in Portland, Oregon. Photograph: Justin Sullivan/Getty Images

"The others said they wanted to be doctors, nurses or soldiers," the former teacher says now. "Berry wrote that he wanted to be a president one day."

Read the second part of the Obama story here