This is a skill that every knitter needs to know and it's very simple.
Use the working yarn that you’ve been knitting with. Cut off the yarn, leaving a couple feet or more. Thread the end into a tapestry needle and pull that through the remaining stitches on your knitting needle.
When all of the stitches are on the yarn, pull it tightly like a drawstring.