The result of a vote among 14 Confederation of African Football (CAF) executive committee members was announced mid-afternoon in a Cairo hotel after the three candidates made short presentations.
The Gabonese were co-hosts with neighbours Equatorial Guinea of the 2012 Cup of Nations.
They will be the second successive central African country to host the championship after Equatorial Guinea this year.
Choosing Gabon ended a 1,529-day saga over who would host the next edition of the biennial African football showpiece.
South Africa were selected as 2017 hosts four years ago, but traded tournaments with 2013 hosts Libya because of post-Moamer Kadhafi-era violence in the north African state.
As deadly Libyan inter-militia fighting intensified, the oil-rich country were forced to withdraw as 2017 hosts as well.
Algeria, Egypt, Gabon, Ghana, Kenya, Sudan and Zimbabwe then applied to stage the 16-nation, three-week tournament.
But CAF dropped Kenya, Sudan and Zimbabwe from the bidding contest, saying they did not meet the criteria to host the tournament.
Kenya (1996) and Zimbabwe (2000) had previously been selected as Cup of Nations hosts only to pull out due to lack of finance.
Egypt later withdrew, saying they did not wish to compete against fellow Arab nation Algeria.
However, security was probably also a factor as the decision came just days after 20 football supporters where killed in a Cairo stampede following clashes with police.
Before the selection of Gabon, north and west African countries staged 10 tournaments each, east Africa five, central Africa four and southern Africa three.
There were two co-hostings — Ghana and Nigeria in 2000, as late replacements for Zimbabwe, and Equatorial Guinea and Gabon three years ago.
Equatorial Guinea became 2015 hosts just two months before the Cup of Nations kicked off last January after Morocco withdrew because they feared visiting supporters could bring the deadly Ebola virus into the country.
CAF president Issa Hayatou, vice-presidents Suketu Patel and Almamy Kabele Camara, and 11 executive committee members chose the 2017 hosts.
Each of the 14 officials, including Algerian Mohamed Raouraoua and Ghanaian Kwesi Nyantakyi, had one vote and the winning nation required at least eight.