PROBLEM TO BE SOLVED: To provide a thermosetting epoxy resin composition for encapsulating an optical semiconductor element excellent in handleability, transparency and crack resistance and smaller in reduction of glass transition temperature than that when conventional flexibility adding agent is added.SOLUTION: There is provided a thermosetting epoxy resin composition for encapsulating an optical semiconductor element containing (A) a prepolymer obtained by reacting (A-1) a triazine derivative epoxy resin having 3 or more epoxy groups in a molecule, (A-2) at least one epoxy resin selected from a bisphenol A type epoxy resin, a bisphenol F type epoxy resin, a hydrogenated bisphenol A type epoxy resin and an alicyclic epoxy resin, (A-3) an acid anhydride curing agent which is a liquid at 50°C, (A-4) a flexibility adding agent selected from polycarbonate polyol and an acryl block copolymer with a ratio of epoxy group equivalence/acid anhydride group equivalence of 0.6 to 2.0 and (B) a curing accelerator consi