Cut a long tail of yarn, put it on a tapestry needle and pull it through all the stitches that are left on the needle. Pull the yarn so the top stitches close into a circle, and then sew the seam down the back of the hat.
Check out Mattress stitch–Amy has video and it works great.