He learned to produce a Patronus in "Harry Potter and the Order of the Phoenix" and was able to cast it throughout the series, including in "Deathly Hallows."
It's important to note that the Patronus takes the form of a stag, which is significant as it was also the form of James Potter's Patronus.