A deadlock occurs when a set of processes are blocked because each process is holding a resource and waiting for another resource held by another process in the set, creating a circular wait. Four necessary conditions must be met for a deadlock to occur: mutual exclusion, hold and wait, no preemption, and circular wait. Deadlocks can be handled through deadlock avoidance, detection and recovery, or prevention. Avoidance methods like Banker's Algorithm use safe state models to prevent deadlocks, while detection algorithms use resource allocation graphs to detect deadlocks. Once detected, deadlocks are recovered through process termination or resource preemption.