The present invention provides an electronic lock structured to include a first bolt configured with an elastic clasp, an electromagnetic device connected to an
input device, a second bolt and a microswitch connected to a
security system, all of which are installed interior of a housing of the electronic lock. The elastic clasp is retained by a protruding edge of the housing, thereby disenabling the first bolt from an arbitrary retracting movement that would otherwise render the lock incapable of being unlocked. The
input device controls the electromagnetic device to induce the elastic clasp and release a retaining state, and then directly rotating a rotating button causes a retracting movement of the first bolt and unlocking of the electronic lock, which simultaneously disconnects the
security system. After unlocking, a front end of the second bolt protrudes out from the housing, whereupon a protruding base of the second bolt is used to press a
steel ball, thereby enabling the second bolt to form a substantially stable position, which ensures effective prevention of mistaken locking and avoids forgetting to lock. Moreover, when in a locked state, the second bolt retracts within the housing and triggers the microswitch to activate the
security system, thereby providing the present invention with security and convenience of operation.