A headgate including pair of upright frame members with a pair of weight members disposed therein which are connected to a pair of stanchions operable to move from an open position to a closed position by pivoting linkages. A release mechanism simultaneously releases the weight members from a first position such that gravity causes the weight members to move from the first position to a second position located at a lower height than the first position upon receiving a signal from a tripping mechanism which automatically detects the presence of an animal, wherein the release of the weight members causes the pair of stanchions to move from an open position, which allows an animal to pass therethrough, to a closed position, which causes the stanchions to close so as to confine the animal.