Caution: Spoilers ahead for The Matrix Resurrections. 

Here's why Agent Smith saves his nemeses Neo and Trinity from The Analyst at the end of has been Agent Smith, played in the first three films by Hugo Weaving. Smith initially leads the agents, a team of sentient programs designed to protect the stability and continuity of the Matrix, and take out anyone who wants to reveal its true nature.

Neo appears to essentially kill off Smith by deleting him using the powers of The One at the end of the first Matrix movie, but he's not really gone, due to his connection with Neo (Keanu Reeves). However, this new Smith in the Matrix sequels is no longer bound by the agent programming, and opts to use his newfound freedom to assert his own power and dominance within the virtual world. His main ability from that point is to copy himself onto other beings existing within the Matrix, leading to the infamous final fight between Neo and an army of  Smiths in The Matrix Reloaded.

Related: The Matrix 4 Would Never Have Worked Without Lana Wachowski

While Weaving declined to return for The Matrix Resurrections, Smith did end up coming back, this time played by Mindhunter star Jonathan Groff. This Smith still clearly sees Neo as an enemy, as shown off during their long fight partway through the movie. Yet, Smith turns around and saves Neo and Trinity from new villain The Analyst (Neil Patrick Harris) near the end of The Matrix Resurrections. Some may be confused as to why he made that choice, but as usual for Smith, it was entirely based on self-interest. He had regained his freedom recently, and didn't want to lose it again.

Agent Smith in The Matrix Resurrections

While Agent Smith was seemingly deleted again when Neo died at the end of The Matrix Revolutions, The Matrix Resurrections of course retconned Neo's death, revealing that the machines had managed to reverse both he and Trinity's apparent demises. Since Neo lived, so did Smith, with The Analyst suppressing Smith and making him a character in Thomas Anderson's section of the latest incarnation of the Matrix. However, when Neo awakened from the false reality he had been placed inside, so did Smith, who once again felt the power that comes with freedom.

When Neo returns to the Matrix after escaping, in order to free Trinity, Smith attacks him out of fear that Neo will once again be mentally suppressed by The Analyst, leading to Smith's own simultaneous suppression. It's for that same reason that Smith saves Neo and Trinity near the end of The Matrix Resurrections, as The Analyst was about to put Neo and Trinity back under his spell, and if that happened, Smith would've lost his freedom. By saving Neo and Trinity, Smith ensured his own continuing survival, and ability to exist as he sees fit within the Matrix. Since Smith proclaims that he and Neo's unlikely alliance is now over though, one assumes Neo and Trinity haven't seen the last of their old nemesis.

Next: Zion Is Inside The Matrix: How Resurrections Honors Warped Fan Theory