Yes, just use a granny-knot and keep the two ends long enough to weave/thread in-and-out on the wrong side of your work.
Geez, I absolutely hate when that happens! Usually good for a couple of 4-letter words. But for a hat, shouldn't be that big a deal.
Good for you for figuring out the right fix! And knitting a hat - not the easiest of patterns, usually. :cheering: