Aliyev's involvement in politics began in 1941, when he worked for the All-Union People's Commissariat of Internal Affairs (NKVD or secret police). He officially joined the Communist Party in 1945 and held a series of responsible posts in government and state security in NAR until 1949. From 1950 to 1964, he worked in the Azerbaijani Ministry of State Security (later renamed the KGB). In 1964, he became the deputy chairman, then in 1967–69, chairman of the Azerbaijani KGB. (Azerbaijan was, until 1991, one of the states of the USSR.) In 1969, he was named first secretary of the Azerbaijani Communist Party (ACP) Central Committee, where he was responsible for purging Azerbaijani nationalists from the government and overseeing state-directed economic development.
Aliyev assumed leading Soviet party posts in the 1970s. In 1971, he became a full member of the Soviet Communist Party Central Committee and in 1976 became a candidate member of the Politburo. He supported the Soviet intervention in Afghanistan in 1979. Because of these efforts, Soviet general secretary Leonid Brezhnev awarded him
several Orders of Lenin and other medals. In 1982, he became a full member of the Politburo, the ruling body of Soviet politics. From 1982 until 1987, he also served as deputy chairman of the Soviet Council of Ministers (equivalent to the vice prime minister).
Despite his support for the election of Mikhail Gorbachev as general secretary of the Communist Party in 1985, in 1987 Aliyev was accused of corruption, ousted from the Politburo, and relieved of his duties as party leader in Azerbaijan. Aliyev lived in Moscow as a private citizen under pension for the next three years.
Upon returning to Azerbaijan in July 1990, Aliyev received a rapturous welcome from kneeling crowds of up to 30,000 individuals. He was elected to the Azerbaijani and NAR Supreme Soviets two months later on a nationalist platform, receiving over 95% of the popular vote. In July 1991, Aliyev resigned his Communist Party membership and, after the abortive coup against Gorbachev, called for total independence for Azerbaijan. Noting that Mutalibov had supported the coup plotters, he denounced Mutalibov's bid for the Azerbaijani presidency and orchestrated a ban on presidential voting in NAR. In September 1991, he was named chairman of the Supreme Soviet of NAR (renamed the Supreme Majlis).
An abortive attempt by the Elchibey government to disarm Suret Huseynov's paramilitary forces in the town of Ganja precipitated the fall of his government and provided the opportunity for Aliyev to assume power. Huseynov, a corps commander in NK, had been fired by Elchibey and blamed for defeats in NK. Returning to his hometown of Ganja in 1993, Huseynov amassed forces and weaponry (obtained from the departing Russian military) that posed an increasing threat to the Elchibey government. In early June 1993, the government launched an attack aimed at defeating Huseynov's forces. This attack was easily repulsed and Huseynov began to march on the Azerbaijani capital of Baku, precipitating a government crisis. Elchibey endorsed Aliyev's election as the new legislative speaker, in effect conceding some power to his political nemesis in a futile bid to retain power. Threatened by Huseynov's approaching forces outside the capital, Elchibey fled Baku, returning to his home village in NAR.
Although Elchibey still claimed to be president of Azerbaijan, Aliyev announced that he was assuming responsibility and power as acting head of state, fulfilling his drive to regain political power. On 24 June, a bare quorum of legislators met and formally stripped Elchibey of his presidential powers, transferring them to Aliyev. A 29 August referendum overwhelmingly expressed lack of confidence in Elchibey's rule, opening the way for a new presidential election. This took place on 3 October 1993, with Aliyev winning almost 99% of the vote against two minor party candidates. Although there were some suppressed coup attempts, Aliyev held onto power until the October 1998 election, which he won with 76% of the vote. International observers reported that, although the voting was much improved over the 1993 election, there was still an unacceptable level of irregularities in the casting of ballots. Since the central election committee is made up entirely of Aliyev supporters, voting is under their control. The Council of Europe, after extending a conditional invitation to Azerbaijan to join its organization, could use the problematic election process as a reason to postpone consideration of Azerbaijan's bid for membership.