With the rapid development of 5G technology, the 5G-AKA protocol, as the core security mechanism of 5G technology, has caught widespread attention. Although the deployment of the 5G-AKA protocol has promoted the high-speed interconnection of communication networks, it has also raised users’ concerns about privacy leakage. During the protocol interaction, operators will collect a large amount of data, and once the data is leaked, it will pose a serious threat to users. Therefore, this study proposes an anonymous authentication and key agreement protocol based on SM2 to enhance the privacy of the user authentication process and minimize the disclosure of user information. It extends the Chinese cryptographic SM2 digital signature algorithm to achieve the signature of multiple messages, combines the ElGamal algorithm to encrypt the user’s identity, and adopts zero-knowledge proof technology to ensure the anonymity of the user credentials, thereby achieving the anonymous authentication of the user’s identity. The protocol protects the identity privacy of legitimate users in network activities and effectively blocks the illegal acquisition of user information. Additionally, the protocol holds the accountability for malicious users, allowing authorized regulatory agencies to restore the user’s identity in a legal process. Finally, protocol experimental evaluations are conducted, with deployment and implementation carried out on Windows and Raspberry Pi 4B platforms. The evaluation results show that the consumed time of the anonymous authentication and key agreement process is at the millisecond level, fully demonstrating the efficiency and practicality of this protocol.