In a nutshell
Two-phase locking keeps concurrent transactions safe by making each one lock the data it touches. Every transaction has a growing phase where it only takes locks, then a shrinking phase where it only releases them — never mixing the two. That discipline forces conflicting transactions to wait their turn, guaranteeing a serializable result, at the cost of possible deadlocks.