The 58-year-old Kayani, who replaced former President Pervez Musharraf as army chief in 2007, was to retire on November 28.
Prime Minister Yusuf Raza Gilani announced the government's decision to extend his tenure during a televised address to the nation.
Gilani said the decision to extend Kayani's term was made after consulting President Asif Ali Zardari to ensure continuity in military operations against extremists and terrorists.
Kayani, who has played a key role in shaping foreign policy, will continue in the important post till 2013.
"This decision has been taken in the light of (Kayani's) effective role in the war against terrorism and in the enforcement of rule of law in the country," Gilani said.
"The nation is going through difficult times in this war against terrorists," he said, adding that Kayani had "successfully led us in this war and his staying on is in our best interests".
"The government is presently engaged in a war against terrorism which is now in a critical stage," Gilani remarked.
This campaign against the terrorists requires continuity of military leadership under the current army chief "who led successful operations in Swat, Malakand and South Waziristan", he added.
"We are confident that under the leadership of Gen Ashfaq Pervez Kayani, the war against terrorism will be taken to its conclusion," Gilani said.
Kayani, the country's 14th army chief, is a former chief of the powerful Inter-Services Intelligence agency. He belongs to the Jhelum region, a part of Punjab province known for producing soldiers. He joined the army in 1971 and fought in the war against India in the same year.
The government's decision ended months of speculation on whether kayani would be given an extension. There had also been reports that the government could create the new post of Chief of Defence Staff to accommodate Kayani following his retirement.
Kayani, who acknowledged earlier this year that the Pakistan Army is "India-centric" because of the unresolved issues between the two countries, initiated several measures to insulate the military from politics soon after assuming the post of army chief.
He withdrew army officers from civilian ministries and departments and barred military officers from meeting politicians without permission. He also played a key role in boosting the morale of troops and improving training standards.
In April this year, the Pakistan Army conducted the "Azm-e-Nau" (New Resolve) exercise in the Cholistan desert to train for the possibility of a conventional war with India.
About 50,000 troops and air force elements were mobilised for Pakistan's largest manoeuvres since 1989.
Gilani had last week said that he would make a final decision on whether to give Kayani an extension. Under the 18th constitutional amendment, it is the Prime Minister's prerogative to decide on the appointment and term of the army chief.
At the same time, Kayani has played a key role in shaping foreign policy, especially Pakistan's relations with the US and India.
He chaired a meeting of federal secretaries at the army General Headquarters to prepare for the Strategic Dialogue with the US.
Foreign Minister Shah Mahmood Qureshi met Kayani and ISI chief, Lt Gen Ahmad Shuja Pasha, at the General Headquarters before calling his Indian counterpart S M Krishna and agreeing to hold bilateral talks in Islamabad on July 15.
Political commentators feel Kayani may have played a pivotal role in the script going wrong during the India-Pakistan Foreign Ministers’ meeting on July 15.
External Affairs Minister Krishna and Foreign Minister Qureshi were said to have made good progress during the first session of their talks. Krishna was to meet Prime Minister Gilani in the afternoon, but there was an inexplicable last-minute switch in schedule following which he met President before the premier.
In the time slot that Krishna was to meet Gilani, Kayani met the Prime Minister. Kayani had also met Zardari.
However, when the talks between the Foreign Ministers resumed after Krishna's two call-ons, the atmosphere totally changed and Pakistan took an unexpectedly stringent posture leading to the deadlock at the talks.
Kayani had also served as deputy military secretary during the first stint of Benazir Bhutto as Prime Minister in the 1980s.
Besides being Chief of Staff of a corps, Kayani has also served as Director General of Military Operations. He is a graduate of Fort Benning in the US, Command and General Staff College at Fort Leavenworth and the National Defence College Islamabad.