The present invention relates to an ophthalmic composition, which comprises ganciclovir and olopatadine; wherein, the mass ratio of ganciclovir to olopatadine is (2‑6):1. The present invention also relates to a preparation method of an ophthalmic composition, comprising: step S1, mixing ganciclovir, olopatadine, an osmotic pressure regulator, a pH regulator and water for injection at a temperature of 90-100°C , to obtain a mixed solution; step S2, at a temperature of 70-80° C., adding a solubilizer, a preservative and water for injection to the mixed solution to obtain the ophthalmic composition. In addition, the present invention also relates to the application of the ophthalmic composition in the preparation of medicines for treating keratitis. The eye drops containing the ophthalmic composition provided by the invention not only have good anti-inflammatory and anti-viral effects, but also can avoid adverse reaction symptoms such as eyelid edema, conjunctival hyperemia, pain and burning sensation in patients with long-term use.