The effects of three-dimensional (3D) magnetic perturbations (MPs) and finite beta (β, i.e., the ratio of plasma kinetic pressure to magnetic pressure) on the instability of collisionless trapped electron mode (CTEM) have been studied. Based on the local 3D equilibrium model, we have derived general expressions for longitudinal invariant and the corresponding precession drift frequency of trapped electrons, which include the synergetic effects of MPs and finite β. It is found that 3D effects can either stabilize or destabilize CTEM instability by analytically solving the linear dispersion relation of CTEM. These effects depend on the poloidal and toroidal mode numbers as well as the phase of 3D MPs. Specially, for the destabilizing phase of MPs, the stabilizing effect of finite β on CTEM can be even reversed when the displacement of magnetic flux surface exceeds a critical value. Moreover, the synergetic effects of 3D MPs with stabilizing phase and finite β can further reduce the required absolute value of negative magnetic shear to completely stabilize CTEM instability. This indicates that 3D MPs might be used as an actuator for lowing the level of anomalous electron heat transport, and thus facilitate the formation of electron internal transport barrier (eITB).