In a demodulate-and-forward (DF) based cooperative communication system, erroneous relaying of the data leads to degradation in the performance of the destination receiver. However, a maximum likelihood (ML) decoder in the destination can improve the receiver performance. For achieving a diversity gain, the Alamouti space-time block code (STBC) can be used in the DF based cooperative system in a distributed manner. In this paper, we derive an ML decoder of the distributed Alamouti STBC for the DF based cooperative system with two imperfect relaying nodes. We also consider a DF cooperative communication system in which one out of two relays is in outage. A piece-wise linear (PL) decoder for the DF cooperative system with the distributed Alamouti code and one relay in outage is proposed. The PL decoder provides approximately the same performance as that of the ML decoder with reduced decoding complexity. We derive the pairwise error probability (PEP) of the proposed ML decoder with binary phase-shift keying constellation. An optimized transmit power allocation for the relays is performed by minimizing an upper bound of the PEP. It is shown by simulations that the proposed ML decoder enables the DF protocol based cooperative system to outperform the same rate amplify-and-forward protocol based cooperative system when both systems utilize the distributed Alamouti STBC.