Llorente, a back-up striker who lives in the shadow of the injured Harry Kane, nudged the ball into the net in the 73rd minute with his hip — a goal that was only given after a VAR decision.
Video review worked in Tottenham's favour again in stoppage time when Sterling looked to have secured City's progress. But as the home fans celebrated and the devastated Spurs players slumped to the turf, the referee determined that Sergio Aguero was offside before crossing to Sterling.
It was a dramatic finish to a game that saw three lead changes and four goals scored in the opening 11 minutes. A fifth in the 21st minute saw City take a 3-2 lead at the break.
Agyero made it 4-2 on the hour mark as City looked to secure a comeback win in the quarter-final tie. Llorente's goal then gave Spurs the away goal advantage they needed to make the semifinals.
The two teams face off again on Sunday morning NZT, a crucial Premier League match as City look to keep up with league leaders Liverpool.
In today's other quarter-final tie, Liverpool thrashed Porto 4-1 to book a semifinal tie with Barcelona.
LIVERPOOL ADVANCE WITH SPURS
Liverpool returned to the semifinals of the Champions League with the attacking trio of Sadio Mane, Mohamed Salah and Roberto Firmino grabbing a goal each.
Virgil van Dijk also scored for Liverpool, which advanced 6-1 on aggregate after winning the first leg 2-0 at home.
Porto started well and showed signs it might be able to reverse the first-leg deficit, but Liverpool took control after Mane scored a goal in the 26th minute that was confirmed by video review after being initially disallowed for offside.
Salah added to the lead in the 65th and Eder Militao scored for Porto in the 69th, but Firmino ended any doubts in the 77th and Van Dijk closed the scoring in the 84th at the Estadio do Dragao.
Liverpool, which lost in the final last season, will now face Barcelona, which eliminated Manchester United 4-0 on aggregate on Wednesday.
Liverpool had barely gotten close to Iker Casillas's goal when Salah picked up a pass inside the area and sent a low pass to Mane, who came sliding in behind the defenders near the far post to open the scoring.
Mane looked offside at first, and few Liverpool players complained when the flag went up, but video review showed he was in legal position before making his run to the ball to score his 14th goal in 21 Champions League appearances.
The goal hurt Porto's morale and the team struggled to keep pushing forward. The pace slowed significantly and Liverpool took advantage, with Salah finding the net from inside the area after a pass by Trent Alexander-Arnold on a quick counterattack.
Firmino, who came off the bench after halftime, and Van Dijk added to the lead with late headers. Porto's lone goal also came through a header by Militao, the defender who is joining Real Madrid at the end of the season.
Mane could have scored his second goal of the game in the 73rd but he missed an open net after dribbling past Casillas on a breakaway.
Porto, which eliminated Roma in the round of 16, had won all of its four home games in the Champions League this season, outscoring opponents 11-3.
It was the second consecutive elimination for the Portuguese champions against Liverpool. The English side routed Porto 5-0 at the Estadio do Dragao in the first leg of the round of 16 last season, with Salah, Firmino and Mane scoring all goals. Liverpool advanced after a scoreless draw at home, and eventually made it to the final where it lost to Real Madrid.
Porto, in the quarterfinals for the first time since 2014-15, was trying to reach the semifinals for the first time since it won the tournament in 2004 under Jose Mourinho for its biggest triumph.
Porto was boosted by the return of two key players who missed the first leg because of yellow-card suspensions: captain Hector Herrera and defender Pepe, a three-time Champions League winner with Real Madrid.
Liverpool coach Juergen Klopp made a series of changes to the lineup from the first leg, revamping the midfield and using Firmino as a second-half substitute.