Aguero put City ahead from the penalty spot in the 21st minute after he had been fouled by Mehdi Benatia, who was sent off.
But Bayern fought back when Xabi Alonso’s free-kick and Robert Lewandowski’s header made it 2-1 at half-time.
However, Aguero rescued City with a cool finish to equalise, before completing his hat-trick with a dramatic winner in stoppage time.
“I think all the big teams need big players, Sergio Aguero is a big player and very important,” said Pellegrini.
“The whole team played until the end, we conceded two unbelievable goals but our whole team kept working and concentrating until the end.”
The win means City, Roma and CSKA Moscow are all level on five points in Group E with one game remaining.
“There are a lot of different options,” Pellegrini, whose side travel to Roma on 10 December, continued. “We are always feeling positive but it does not always depend on what we can do.
“We must try to have our chance to the end and the way to have that chance is to win at Roma.”
MORE: Man United latest news
MORE: Arsenal latest news
MORE: Chelsea latest news
MORE: Liverpool latest news