Mozambique's parliament has approved a draft law increasing compulsory military service from two to five years for general service and up to six for special forces.
It is intended to help the army retain more soldiers and be more professional.
Neighbouring countries have sent troops to help Mozambique tackle an Islamist insurgency in the north.
The authorities hope longer military service would remove the need for foreign support against the jihadists.
The new law may still face amendments and must be assented to by the president to become law.
Mozambicans have to register with the armed forces when they reach 18.
However, not everyone ends up joining, as people can seek exemption on health or other grounds.
The new law makes the armed forces responsible for sending conscription summonses upon authorisation by the defence minister.
It imposes criminal liability for people who disobey summonses and fines for companies that prevent workers from joining.
The extension of military service was passed by lawmakers from the ruling Front for the Liberation of Mozambique (Frelimo), which has a parliamentary majority, supported by a smaller opposition party, the Democratic Movement of Mozambique (MDM).
The main opposition party, the ex-rebel Renamo movement which has been boycotting parliamentary sessions to protest against the outcome of recent municipal elections, did not vote.
Defence Minister Cristóvão Chume on Thursday said the military needed to be modern and more professional to be able to face challenges against national security and sovereignty.
"Our country is currently facing threats of a hybrid and diffuse nature, with connections to transnational organised crime. To combat them, they require greater professionalisation," Mr Chume told parliament.
"We will have better soldiers. Currently, they train for a year, are deployed to the field of counter-terrorism operations and only stay there for six months, then leave.
"With this law, we will allow more and place more experienced people to fight terrorism," he said.
On Wednesday, President Filipe Nyusi told a defence forces forum that the country's military must be prepared to work without foreign support.
Troops from Rwanda and the southern African bloc Sadc have been conducting joint operations to fight the insurgency by groups linked to Islamic State since 2021.
However, the country still experiences sporadic attacks.
Mozambique also faces other national security threats include piracy, sea pollution, illegal fishing and the trafficking of drugs and people.
The six-year insurgency has claimed the lives of at least 4,000 people and displaced nearly one million others from the northern Cabo Delgado province.
It has stalled operations to develop and tap the country's vast natural gas deposits, which were discovered in Cabo Delgado in 2010.
There have been mixed reactions to the bill - some have noted that it will allow the government and the conscripts time to plan better, as many of the conscripts are demobilised at the end of the two years and go home without anything to do.
Some however have expressed concern that the extended military service might delay young adults entering the job market.
Some 110,000 personnel currently work for the Mozambican armed forces. It is not clear to what extent the longer military service will increase their numbers.