Here's why:
* "Listening attentively" is the subject of the first sentence and is a noun phrase.
* "It" in the second sentence refers back to the action of "listening attentively".
Therefore, the antecedent of "it" is the noun phrase "listening attentively".