The court said: "Sweden's security is of heavy importance and the administrative court has taken into account that only the Security Police and the armed forces together have an overall picture regarding the security situation and the threat to Sweden."
The ban was announced in October 2020, with the telecoms regulator PTS saying it was based on security concerns outlined by the country's security service, SAPO. It was the second ban on Huawei to be openly announced by an European country, with the UK being the first.
In a statement issued after the verdict, Ericsson said the decision "may adversely impact the economic interests of Sweden and Swedish industry, including those of Ericsson."
Huawei had challenged the decision in the courts, and parts of the restriction were put on hold, but Wednesday's decision means that any chance of selling 5G gear in Sweden is gone.
Kenneth Fredriksen, Huawei's executive vice-president, Central East Europe and Nordic Region, said: "It's not unexpected based on the fact that the court is also leading their conclusions on basically the assumptions being made by SAPO.
"We will continue to fight for our right to be in the (Swedish) market."
Ericsson's business came under a cloud in July last year when the US Department of Defence released a list showing that its Chinese partner, Panda Electronics Corporation, had links to the Chinese military.
Huawei Australia has been contacted for comment.