Using a social dilemma game, we study the cooperative behavior of individuals who reintegrate their group after being excluded by their peers. We manipulate the length of exclusion and whether this length is imposed exogenously or results from a vote. We show that people are willing to exclude the least cooperators and they punish more, and more severely, chronic defections. In return, a longer exclusion has a higher disciplining effect on cooperation after reintegration, but only when the length of exclusion is not chosen by group members. Its relative disciplining effect is smaller when the length of exclusion results from a vote. In this environment, a quicker reintegration also limits retaliation. The difference in the impact of long vs. short exclusion on retaliation is larger when the length of exclusion is chosen by group members than when it is exogenous. Post-reintegration cooperation and forgiveness depend not only on the length of exclusion but also on the perceived intentions of others when they punish.