Kibaki entered elective office on the KANU ticket in 1963. He won the Donholm Constituency (now Makadara) in Nairobi Province, and became a Member of Parliament (MP). He was reelected the MP in 1969. President Kenyatta appointed him parliamentary secretary to the minister of finance (1963–65). He also served as minister at the Ministry of Commerce and Industry until 1969. From 1970 to 1978, he was assigned to the Ministry of Finance and Economic Planning. He changed his political base from Nairobi to Othaya and was elected here in 1974 on a KANU ticket. In 1979, 1983, and 1988 he was reelected an MP for the Othaya constitutency. He was also branch chairman from 1974 until 1991 for KANU. He resigned from KANU in 1991 to found the Democratic Party (DP).
Upon replacing Kenyatta in 1978, President Daniel Arap Moi appointed Kibaki his vice president. Kibaki continued to serve in the Ministry of Finance and Economic Planning and was moved in 1983 to the Ministry of Home Affairs and National Heritage in 1988. Perhaps mistrustful of Kibaki, Moi demoted him and reassigned him to the Ministry of Health, where Kibaki nevertheless earned accolades. From 1978 to 1988, Kibaki also held positions as leader of government business and chairman of the sessional committee and KANU vice president. He took an active leadership role in Parliament: he served as member and chair of the Public Accounts Committee (1997–2002), and also was a member of the House Business Committee (1998–2002).
Following the authorization of multiparty competition in elections, Kibaki left KANU to form the DP on 25 December 1991. Despite accusations from the loyal opposition that the DP had been created as a mole party to fracture the "real" opposition, Kibaki vied for the presidency in the 1992 elections and came in third behind Moi and Kenneth Matiba. In 1997 he ran again on the DP ticket, coming in second to Moi.
With the DP having become the official opposition party in January 1998, Kibaki rose in standing to leader of the official opposition. In the run-up to the December 2002 election, Kibaki organized a coalition of opposition parties, the National Rainbow Coalition (NARC). He was sworn in on 30 December 2002 as Kenya's third president.