Supporters of President Uhuru Kenyatta celebrate in Kikuyu Town, Kenya, after he was declared the winner of the presidential election, Friday, Aug. 11, 2017. Kenya's election commission announced Friday that President Uhuru Kenyatta has won a second term as opposition candidate Raila Odinga claimed the vote was rigged. (AP Photo/Jerome Delay)

Uhuru Kenyatta, centre left, and his deputy William Ruto, centre right, react after the announcement in the presidential race at the Centre in Bomas, Nairobi, Kenya, Friday, Aug.11, 2017. Kenya's election commission announced Friday that President Uhuru Kenyatta has won a second term with 54 percent of the vote, and called the vote "credible, fair and peaceful", while opposition candidate Raila Odinga claimed the vote was rigged. (AP Photo/ Sayyid Abdul Azim)

The Chairman of the Independence Electoral and Boundaries Commission, Wafula Chebukati , left, hands over the certificate to Uhuru Kenyatta, centre right, after announcing him the winner in the presidentail race at the Centre in Bomas, Nairobi, Kenya, Friday, Aug.11, 2017. The commission said Kenyatta won Tuesday's election with 54 percent of the vote. It called the vote "credible, fair and peaceful." (AP Photo/ Sayyid Abdul Azim)

Supporters of Kenya's President Uhuru Kenyatta cheer as they hear the election results, at the Kenya International Conference Center in downtown Nairobi, Kenya, Friday, Aug. 11, 2017. Kenya's election commission announced Friday that President Uhuru Kenyatta has won a second term as opposition candidate Raila Odinga claimed the vote was rigged. (AP Photo/Ben Curtis)

Supporters of President Uhuru Kenyatta celebrate in Kikuyu Town, Kenya, after he was declared the winner of the presidential election, Friday, Aug. 11, 2017. Kenya's election commission announced Friday that President Uhuru Kenyatta has won a second term as opposition candidate Raila Odinga claimed the vote was rigged. (AP Photo/Jerome Delay)

Supporters of President Uhuru Kenyatta celebrate in Kikuyu Town, Kenya, after he was declared the winner of the presidential election, Friday, Aug. 11, 2017. Kenya's election commission announced Friday that President Uhuru Kenyatta has won a second term as opposition candidate Raila Odinga claimed the vote was rigged. (AP Photo/Jerome Delay)

Supporters of President Uhuru Kenyatta celebrate in Kikuyu Town , Kenya, after he was declared the winner of the presidential election, Friday, Aug. 11, 2017. Kenya's election commission announced Friday that President Uhuru Kenyatta has won a second term as opposition candidate Raila Odinga claimed the vote was rigged. (AP Photo/Jerome Delay)

Uhuru Kenyatta, addresses the crowd after the announcement in the presidential race at the Centre in Bomas, Nairobi, Kenya, Friday, Aug.11, 2017. Kenya's election commission announced Friday that President Uhuru Kenyatta has won a second term as opposition candidate Raila Odinga claimed the vote was rigged. The commission said Kenyatta won Tuesday's election with 54 percent of the vote. It called the vote "credible, fair and peaceful." (AP Photo/ Sayyid Abdul Azim)

Uhuru Kenyatta , left, and William Ruto his deputy react, after the announcement in the presidential race at the Centre in Bomas, Nairobi, Kenya, Friday, Aug.11, 2017. Kenya's election commission announced Friday that President Uhuru Kenyatta has won a second term as opposition candidate Raila Odinga claimed the vote was rigged. The commission said Kenyatta won Tuesday's election with 54 percent of the vote. It called the vote "credible, fair and peaceful." (AP Photo/ Sayyid Abdul Azim)

Uhuru Kenyatta, left, and his deputy William Ruto, react after the announcement in the presidential race at the Centre in Bomas, Nairobi, Kenya, Friday, Aug.11, 2017. Kenya's election commission announced Friday that President Uhuru Kenyatta has won a second term with 54 percent of the vote, and called the vote "credible, fair and peaceful", while opposition candidate Raila Odinga claimed the vote was rigged. (AP Photo/ Sayyid Abdul Azim)

Supporters of President Uhuru Kenyatta celebrate in Kikuyu Town, Kenya, after he was declared the winner of the presidential election, Friday , Aug. 11, 2017. Kenya's election commission announced Friday that President Uhuru Kenyatta has won a second term as opposition candidate Raila Odinga claimed the vote was rigged. (AP Photo/Jerome Delay)

A man carrying masks with the image of Kenya's President Uhuru Kenyatta stands as supporters wait an expected announcement of election results, at the Kenya International Conference Center in downtown Nairobi, Kenya Friday, Aug. 11, 2017. Kenyans on Friday awaited the official results of Tuesday's disputed election as hundreds of riot police patrolled the capital. (AP Photo/Ben Curtis)

A man carrying masks with the image of Kenya's President Uhuru Kenyatta stands as supporters wait an expected announcement of election results, at the Kenya International Conference Center in downtown Nairobi, Kenya Friday, Aug. 11, 2017. Kenyans on Friday awaited the official results of Tuesday's disputed election as hundreds of riot police patrolled the capital. (AP Photo/Ben Curtis)

Supporters of Kenya's President Uhuru Kenyatta cheer as they await an expected announcement of election results, at the Kenya International Conference Center in downtown Nairobi, Kenya Friday, Aug. 11, 2017. Kenyans on Friday awaited the official results of Tuesday's disputed election as hundreds of riot police patrolled the capital. (AP Photo/Ben Curtis)

A man carrying masks with the image of Kenya's President Uhuru Kenyatta stands as supporters wait an expected announcement of election results, at the Kenya International Conference Center in downtown Nairobi, Kenya Friday, Aug. 11, 2017. Kenyans on Friday awaited the official results of Tuesday's disputed election as hundreds of riot police patrolled the capital. (AP Photo/Ben Curtis)

Supporters of Kenya's President Uhuru Kenyatta cheer as they watch the television ahead of an expected announcement of election results, in a small cafe in the pro-Kenyatta stronghold of Dagoretti, on the outskirts of Nairobi, Kenya Friday, Aug. 11, 2017. Kenyans on Friday awaited the official results of Tuesday's disputed election as hundreds of riot police patrolled the capital, while the opposition requested access to the election commission's servers to confirm whether alleged hacking took place. (AP Photo/Ben Curtis)

Two men who shape and sell baseball caps at a street stall joke together as they await an expected announcement of election results, in the pro- President Uhuru Kenyatta stronghold of Dagoretti, on the outskirts of Nairobi, Kenya Friday, Aug. 11, 2017. Kenyans on Friday awaited the official results of Tuesday's disputed election as hundreds of riot police patrolled the capital, while the opposition requested access to the election commission's servers to confirm whether alleged hacking took place. (AP Photo/Ben Curtis)

A supporter of Kenya's President Uhuru Kenyatta wears a mask with his image as he drives his "matatu" public minibus in the pro-Kenyatta stronghold of Dagoretti, on the outskirts of Nairobi, Kenya Friday, Aug. 11, 2017. Kenyans on Friday awaited the official results of Tuesday's disputed election as hundreds of riot police patrolled the capital, while the opposition requested access to the election commission's servers to confirm whether alleged hacking took place. (AP Photo/Ben Curtis)

Patrons in a bar in Kikuyu Town, Kenya, wait for the announcement of the presidential election's final results Friday, Aug. 11, 2017. The election commission urged Kenyans to be patient as they await the official results of Tuesday's disputed election, though the counting process has been repeatedly delayed. (AP Photo/Jerome Delay)

The Chairman of the Independence Electoral and Boundaries Commission, Wafula Chebukati gives a media briefing at the Centre in Bomas, Nairobi, Kenya, Friday, Aug. 11, 2017, as people wait to hear the announcement of the winner of presidential race between incumbent President Uhuru Kenyatta and main opposition leader Raila Odinga. The counting process has been repeatedly delayed, and the election commission urged Kenyans to be patient as they wait for the official results of Tuesday's disputed election. (AP Photo/ Sayyid Abdul Azim)

A supporter of President Uluru Kenyatta holds up a Kenyan flag in Kikuyu town, Kenya, in anticipation of the announcement of the presidential election's final results Friday, Aug. 11, 2017. The election commission urged Kenyans to be patient as they await the official results of Tuesday's disputed election, though the counting process has been repeatedly delayed.(AP Photo/Jerome Delay)

Independence Electoral and Boundaries Commission staff are busy counting the results at the Centre in Bomas, Nairobi, Kenya, Friday, Aug.11, 2017, as people wait to hear the announcement of the winner of presidential race between incumbent President Uhuru Kenyatta and main opposition leader Raila Odinga. The counting process has been repeatedly delayed, and the election commission urged Kenyans to be patient as they wait for the official results of Tuesday's disputed election.(AP Photo/ Sayyid Abdul Azim)

Foreign dignitaries wait in the Independence Electoral and Boundaries Commission Centre in Bomas, Nairobi, Kenya, Friday, Aug. 11, 2017, to hear the announcement of the winner of presidential race between incumbent President Uhuru Kenyatta and main opposition leader Raila Odinga. The counting process has been repeatedly delayed, and the election commission urged Kenyans to be patient as they wait for the official results of Tuesday's disputed election.(AP Photo/ Sayyid Abdul Azim)

Independence Electoral and Boundaries Commission staff busy counting the ballots at the Centre in Bomas, Nairobi, Kenya, Friday, Aug. 11, 2017, as people wait to hear the announcement of the winner of presidential race between incumbent President Uhuru Kenyatta and main opposition leader Raila Odinga. The counting process has been repeatedly delayed, and the election commission urged Kenyans to be patient as they wait for the official results of Tuesday's disputed election. (AP Photo/ Sayyid Abdul Azim)

A supporters of President Uluru Kenyatta walks with a Kenyan flag in anticipation of the announcement of the presidential election's final results Friday, Aug. 11, 2017, in Kikuyu Town, Kenya. The election commission urged Kenyans to be patient as they await the official results of Tuesday's disputed election, though the counting process has been repeatedly delayed.(AP Photo/Jerome Delay)

A supporter of President Uluru Kenyatta hands out posters in Kikuyu town, Kenya, in anticipation of the announcement of the presidential election's final results Friday, Aug. 11, 2017. The election commission urged Kenyans to be patient as they await the official results of Tuesday's disputed election, though the counting process has been repeatedly delayed. (AP Photo/Jerome Delay)

Supporters of President Uluru Kenyatta celebrate in anticipation of the announcement of the presidential election's final results Friday , Aug. 11, 2017. Several days after Kenyans voted in elections, the country on Friday was awaiting an announcement of official results that have become a source of bitter contention following opposition allegations of vote-rigging. While most of the country was calm, hundreds of riot police patrolled Nairobi's central business district and opposition supporters burned tires and blocked roads in several areas.(AP Photo/Jerome Delay)

Supporters of President Uluru Kenyatta celebrate in anticipation of the announcement of the presidential election's final results Friday , Aug. 11, 2017. Several days after Kenyans voted in elections, the country on Friday was awaiting an announcement of official results that have become a source of bitter contention following opposition allegations of vote-rigging. While most of the country was calm, hundreds of riot police patrolled Nairobi's central business district and opposition supporters burned tires and blocked roads in several areas (AP Photo/Jerome Delay)

Supporters of Kenyan opposition leader and presidential candidate Raila Odinga demonstrate in the Kibera slum in Nairobi, Kenya. Friday Aug. 11, 2017. Several days after Kenyans voted in elections, the country on Friday was awaiting an announcement of official results that have become a source of bitter contention following opposition allegations of vote-rigging. While most of the country was calm, hundreds of riot police patrolled Nairobi's central business district and opposition supporters burned tires and blocked roads in several areas. (AP Photo/Khalil Senosi)

Kenyans listen to the radio on their phone, waiting for the final results to be announced in a restaurant in Nairobi's Mathare slum Friday , Aug. 11, 2017. Several days after Kenyans voted in elections, the country on Friday was awaiting an announcement of official results that have become a source of bitter contention following opposition allegations of vote-rigging. While most of the country was calm, hundreds of riot police patrolled Nairobi's central business district and opposition supporters burned tires and blocked roads in several areas. (AP Photo/Jerome Delay)

Supporters of Kenyan opposition leader and presidential candidate Raila Odinga holds a machete in the Kibera slum Nairobi, Kenya. Friday Aug. 11, 2017. Several days after Kenyans voted in elections, the country on Friday was awaiting an announcement of official results that have become a source of bitter contention following opposition allegations of vote-rigging. While most of the country was calm, hundreds of riot police patrolled Nairobi's central business district and opposition supporters burned tires and blocked roads in several areas. (AP Photo/Khalil Senosi)

Supporters of Kenyan opposition leader and presidential candidate Raila Odinga demonstrate in the Kibera slum in Nairobi, Kenya. Friday Aug. 11, 2017. Several days after Kenyans voted in elections, the country on Friday was awaiting an announcement of official results that have become a source of bitter contention following opposition allegations of vote-rigging. While most of the country was calm, hundreds of riot police patrolled Nairobi's central business district and opposition supporters burned tires and blocked roads in several areas. (AP Photo/Khalil Senosi)

Supporters of Kenya's President Uhuru Kenyatta cheer as they hear the election results, at the Kenya International Conference Center in downtown Nairobi, Kenya, Friday, Aug. 11, 2017. Kenya's election commission announced Friday that President Uhuru Kenyatta has won a second term as opposition candidate Raila Odinga claimed the vote was rigged. (AP Photo/Ben Curtis)

Supporters of Kenya's President Uhuru Kenyatta cheer as they hear the election results, at the Kenya International Conference Center in downtown Nairobi, Kenya, Friday, Aug. 11, 2017. Kenya's election commission announced Friday that President Uhuru Kenyatta has won a second term as opposition candidate Raila Odinga claimed the vote was rigged. (AP Photo/Ben Curtis)

Uhuru Kenyatta, left, and his deputy William Ruto, react after the announcement in the presidential race at the Centre in Bomas, Nairobi, Kenya, Friday, Aug.11, 2017. Kenya's election commission announced Friday that President Uhuru Kenyatta has won a second term with 54 percent of the vote, and called the vote "credible, fair and peaceful", while opposition candidate Raila Odinga claimed the vote was rigged. (AP Photo/ Sayyid Abdul Azim)

Uhuru Kenyatta, addresses the crowd after the announcement in the presidential race at the Centre in Bomas, Nairobi, Kenya, Friday, Aug.11, 2017. Kenya's election commission announced Friday that President Uhuru Kenyatta has won a second term as opposition candidate Raila Odinga claimed the vote was rigged. The commission said Kenyatta won Tuesday's election with 54 percent of the vote. It called the vote "credible, fair and peaceful." (AP Photo/ Sayyid Abdul Azim)

In announcing the results of Tuesday's contest, the election commission said Kenyatta won a second term with 54 percent in balloting it called "credible, fair and peaceful."

Hundreds of riot police were in the streets of the capital, Nairobi, amid fears of further protests by opposition supporters, who called the vote a "charade" and said challenging the outcome in court wasn't an option.

Kenyatta, the 55-year-old son of Kenya's first president after independence from Britain, appealed for calm and unity after the bitter campaign.

"Kenya belongs to all of us," he said. "Let us shun violence and let us refuse to be used for short-term political gain."

He said he was extending a "hand of friendship" to "our older brother," Odinga.

"We need and must continue to work together for the welfare of our people and in order to keep this country united," said Kenyatta, who also defeated Odinga in 2013. "We reach out to you. We reach out to your supporters."

The election was a test of the stability of the East African economic power as many recalled the postelection bloodshed a decade ago that left more than 1,000 dead.

"We have seen the results of political violence and I am certain there is no single Kenyan who would wish to go back to those days," Kenyatta said.

Kenya had been relatively calm since the election but had braced for possible violence Friday night with police in the central business district.

Although celebrations by backers of Kenyatta were reported in several cities across Kenya, gunshots and screams were heard in at least two areas populated by Odinga supporters, according to police and a witness.

The gunfire rang out in the Nairobi slum of Kibera and in the southwestern city of Kisumu, the witnesses said. Youths also were reported to be throwing stones at cars in Kibera.

"There are gunshots all over; we don't know how it will end but we are praying for peace," said Kisumu resident Lucas Odhiambo, adding that people were bellowing through "vuvuzela" noisemakers when the results were announced "and police moved in."

Earlier in the day, opposition supporters burned tires and blocked roads in several areas.

The election commission rejected claims by Odinga, a former prime minister, that its database was hacked and results manipulated against him.

The long wait for election results increased tensions in the nation of 45 million people, though the commission by law had until Aug. 15 to announce them. At least three people were killed in clashes between police and opposition supporters this week.

Odinga alleged that hackers infiltrated the election commission's computer system in favor of his opponent. He claimed the hackers used the identity of Christopher Msando, an election official in charge of managing information technology systems. Officials had announced on July 31 that Msando had been tortured and killed.

In addition, the American CEO of an election data company working for Odinga was deported last weekend.

The election commission said there was a hacking attempt but it failed, and that Odinga's camp had no right to declare him as the winner.

Earlier Friday, the opposition said it had asked for access to the commission's servers to confirm whether the alleged hacking took place. If granted, it said it would accept the results, even if they showed that Kenyatta won.

Kenyatta has not commented on Odinga's allegations.

International election observers have said they saw no signs of interference with the vote. Election officials spent recent days confirming provisional results with checks of documents from polling stations nationwide.

U.S. Ambassador Robert F. Godec said any disputes should be dealt with through legal channels. "No Kenyan should die because of an election," he said.

This may have been the last chance at the presidency for the 72-year-old Odinga after three unsuccessful attempts.

Odinga lost the 2007 election that was followed by the violence that was fueled by ethnic tensions. He also lost the 2013 vote to Kenyatta and took allegations of vote-tampering to the Supreme Court, which rejected his case.