Transactions in databases ensure data integrity by grouping operations that either succeed together or fail together, maintaining consistency and reliability.