The present invention relates to a topical ophthalmic formulation for use in the treatment of ocular pain comprising gabapentin or a salt thereof and nanoparticles of copolymers of polyethylacrylate, methyl-methacrylate and chlorotrimethyl-ammonioethylmethacrylate having a content of quaternary ammonium groups between 4.5 and 12%.