By Zaffar Abbas
BBC correspondent in Islamabad
The upper house of Pakistan's parliament has passed a bill allowing Gen Pervez Musharraf to remain as both president and army chief until 2007.
Musharraf had promised to step down from the army post
The bill has already been passed by lower house and will come into effect on 31 December, when the president was due to step down as army chief.
Opposition lawmakers opposed the move to extend his tenure.
President Musharraf had earlier pledged to quit his military post by the end of this year.
Unlike in the lower house, where the government had virtually bulldozed the highly controversial bill through, a fully-fledged debate took place in the upper house, the senate.
For nearly a week, opposition members from both the secular and religious parties argued, and even pleaded, against the move.
Leaders of the opposition Islamic alliance called it a breach of the agreement reached between them and the government, and even threatened to disown the constitutional amendment that legitimised President Musharraf's military rule.
Members of Benazir Bhutto's Pakistan Peoples Party and some regional groups said the move was not only unconstitutional but also amounted to surrendering the parliament's sovereignty.
But the arguments appeared to have no effect on the governing party members.
Supporting the move they said it was crucial for President Musharraf to keep both offices for the sake of country's security, particularly for dealing with al-Qaeda.
When the bill was moved for a vote, all the opposition members stood on their seats and tried to disrupt the proceedings shouting "Go Musharraf, go" and "No uniform, no".
Government senators ignored the protest and got the bill passed with the help of a simple majority.
Some legal experts say the president is bound by the constitution to quit his military post. They say the passing of an ordinary law cannot override the provisions of the constitution.
The government, however, insists it has fulfilled all legal requirements.
The final decision still rests with President Musharraf.
Although he has clearly inclined towards keeping both offices, many people in government say he might hold off making a final announcement until the deadline of 31 December.