This would be Dream Eater Merry (Yumekui Merry)
The scene you are talking about is the first scene of the anime where Yumeji Fujiwara, the main character, is running away from cats in a nightmare he is having. The next time he has the dream, he encounters the leader called "Chaser" John Doe who wields a chainsaw.
After trying to escape, Fujiwara encounters a girl called Merry Nightmare who ends up fighting John.
.
Both Merry and John are Dream Demons from another world, and Dream Demons can possess people's bodies to enter the real world. However, Merry has no memories and she doesn't need to possess a body.
As for Merry's powers sourcing from her hat, I don't think this is the case. Rather, I think she just really, really, really loves her had. (I haven't seen the series in a while, but I think I remember her being able to fight without her hat).
As for the dimension of the nightmares, these are actually just people's dreams which Merry can enter and drag Fujiwara into. Other humans who appear in dreams are either possessed by a Dream Demon who has entered the dream (i.e. "Garden" Engi Threepiece) or own the dream themselves.
This video shows the scene of Fujiwara meeting John Doe.
While what I describe is from the anime, there is a manga (the original material) and I believe the beginning of the manga would be the same.