BERLIN—Huawei Technologies Inc. secured a commitment to build part of Germany’s 5G infrastructure, strengthening its position in Europe’s largest economy despite calls from lawmakers to bar the Chinese company.

Telefónica SA, one of three major mobile operators in Germany, said Wednesday it planned to use equipment from Huawei and Finland-based Nokia Corp. to build its 5G wireless network in the country—subject to Huawei equipment meeting government security standards.

“Telefónica...