I would argue that Horatio plays an essential role in Hamlet. Primarily, he exists to ground the action of the drama in truth and reality. This is very important, not least because those two qualities are often in short supply among the members of the Danish court. Everyone's playing their own little game, and in the process creating their own truth, their own reality.
Horatio's moderating presence acts as a necessary counterbalance to all the madness that descends upon Elsinore. Without Horatio, that's all it would be: madness. But thanks to him, we're able to take a step back and gain a broader, more rational perspective on things, a perspective which Hamlet is singularly unable to provide.
Horatio's role as a confidant to his best friend is also important. Hamlet can soliloquize from now until Doomsday and yet we still wouldn't have much insight into what he's really and thinking. It's only through his conversations with Horatio that we get a better idea of what's really going on inside that tortured mind of his. And Hamlet for one is most grateful for this, paying tribute to Horatio for his virtue and self-control, qualities which he himself noticeably lacks:
Horatio, thou art e'en as just a man/As e'er my conversation cop'd withal. (Act III Scene ii).