Locking device for a leaf moveably mounted in a frame, preferably a locking device for a door in a building, comprising a bolt assembly mountable on the frame or on the leaf and a bolt receiving device mountable on the leaf or on the frame, wherein it is provided that - the bolt assembly has a moveably mounted bolt element formed as a latch or a bolt, and - the bolt receiving device has a bolt receiver receiving the bolt element in the locking position, and the bolt receiving device and the bolt element have a magnet device, and - the bolt receiving device and the bolt assembly are allocated to each other for forming the locking position of the bolt element in such a way that the bolt element is movable into the locking position by means of the magnetic force effect of the magnet device and can be brought into engagement with the bolt receiver, - the bolt element can be brought out of engagement with the magnet device for forming an unlocking position of the bolt element, by the bolt element and/or the bolt receiver having an outlet bevel and the bolt element and the bolt receiver being allocated to each other in such a way that the bolt element is impinged via the outlet bevel by means of interaction of the bolt receiver and bolt element during the opening process in the unlocking direction, and - the magnet device of the bolt receiving device is or are formed as an electromagnet, characterised in that - the electromagnet is formed to be able to reverse its polarity, and the bolt element has a permanent magnet. comprising a bolt assembly mountable on the frame or on the leaf and a bolt receiving device mountable on the leaf or on the frame, wherein it is provided that - the bolt assembly has a moveably mounted bolt element formed as a latch or a bolt, and - the bolt receiving device has a bolt receiver receiving the bolt element in the locking position, and the bolt receiving device and the bolt element have a magnet device, and - the bolt receiving device and the bolt assembly are allocated to each other for forming the locking position of the bolt element in such a way that the bolt element is movable into the locking position by means of the magnetic force effect of the magnet device and can be brought into engagement with the bolt receiver, - the bolt element can be brought out of engagement with the magnet device for forming an unlocking position of the bolt element, by the bolt element and/or the bolt receiver having an outlet bevel and the bolt element and the bolt receiver being allocated to each other in such a way that the bolt element is impinged via the outlet bevel by means of interaction of the bolt receiver and bolt element during the opening process in the unlocking direction, and - the magnet device of the bolt receiving device is or are formed as an electromagnet, characterised in that - the electromagnet is formed to be able to reverse its polarity, and the bolt element has a permanent magnet. - the bolt assembly has a moveably mounted bolt element formed as a latch or a bolt, and - the bolt receiving device has a bolt receiver receiving the bolt element in the locking position, and the bolt receiving device and the bolt element have a magnet device, and - the bolt receiving device and the bolt assembly are allocated to each other for forming the locking position of the bolt element in such a way that the bolt element is movable into the locking position by means of the magnetic force effect of the magnet device and can be brought into engagement with the bolt receiver, - the bolt element can be brought out of engagement with the magnet device for forming an unlocking position of the bolt element, by the bolt element and/or the bolt receiver having an outlet bevel and the bolt element and the bolt receiver being allocated to each other in such a way that the bolt element is impinged via the outlet bevel by means of interaction of the bolt receiver and bolt element during the opening process in the unlocking direction, and - the magnet device of the bolt receiving device is or are formed as an electromagnet, - the electromagnet is formed to be able to reverse its polarity, and the bolt element has a permanent magnet.