The ruling will strengthen Lungu's hand at a time when Zambia, Africa's second largest copper producer, is grappling with mounting debt and an economic slump caused by depressed commodity prices.
Lungu's first period in office lasted only one year and six months, when he took over after the death of the previous elected president, Michael Sata. He then won election in a disputed vote to a second, full term in August 2016.
Lungu's supporters argued that the constitution says a president is only deemed to have served a term if he is in office for at least three years of the full five-year term.
Constitutional Court President Hildah Chibomba said the ruling by the seven judges of the court had been unanimous.
"Our answer is that (Lungu's first) presidential tenure of office...cannot be considered as a full term," Chibomba said.
Opposition leader Hakainde Hichelema, who heads the United Party for National Development (UPND), criticised the ruling as effectively opening the way to a third term for Lungu.
"For now, we would like to clearly state that no one is entitled to a third term of office as president of this country," Hichelema said. "This is because when courts fail to protect citizens, (they) have the power to map their own destiny through people power."
Elias Chipimo, who heads the smaller National Restoration Party, said on Twitter: "The Constitutional Court may just have done more to undermine confidence in our judiciary than at any other time in our history."
The opposition cannot appeal the ruling as the Constitutional Court is the highest tribunal in Zambia.
Lungu told supporters in November that Zambian judges could plunge the southern African country into chaos if they made any "adventurous" rulings, according to the Zambia Daily Mail and Times of Zambia.
Lungu has said Zambia is committed to improving the transparency of its debt management and will ensure that debt levels remain sustainable.
The International Monetary Fund rejected Zambia's borrowing plans earlier this year and said the southern African country was at high risk of debt distress, unnerving investors holding Zambian debt. (Writing by James Macharia Editing by Mark Heinrich)
(This story has not been edited by Devdiscourse staff and is auto-generated from a syndicated feed.)