For Unity users, Moments is a fantastic, free plugin which automatically and continuously records the last N seconds of gameplay and dumps that buffer to a .gif on-demand, asynchronously in the background without interrupting your game. You can easily configure the length of the buffer, the frame rate, the resolution, and the amount of color compression.
I integrated it into Legacy of the Elder Star in about ten minutes; it runs constantly in the background during gameplay and saves a Twitter-friendly .gif of the last 4 seconds whenever you hit G. All the animated gifs I've posted on the official website, our itch.io page, our social media accounts, and even the super high-res ones we put on our (now-defunct) Kickstarter page, were all captured using Moments.