We propose a contention-based random-access protocol, designed for wireless networks where the number of users is not a priori known. The protocol operates in rounds divided into equal-duration slots, performing at the same time estimation of the number of users and resolution of their transmissions. The users independently access the wireless link on a slot basis with a predefined probability, resulting in a distribution of user transmissions over slots, based on which the estimation and contention resolution are performed. Specifically, the contention resolution is performed using successive interference cancellation which, coupled with the use of the optimized access probabilities, enables throughputs that are substantially higher than the traditional slotted ALOHA-like protocols. The key feature of the proposed protocol is that the round durations are not a priori set and they are terminated when the estimation/contention-resolution performance reach the satisfactory levels.