With the rapid development of cognitive radio technologies, spectrum sharing becomes a promising approach to improving the efficiency of spectrum utilization and mitigating the spectrum scarcity problem. Previous research on cognitive networks argues that secondary users can only work under a low-transmission power in an underlay spectrum sharing model, especially when the primary transmitter is far away from the primary receiver. Motivated by the idea of cooperative communications, in this paper, we propose a cooperative framework in which a primary transmitter, being aware of the existence of the secondary network, may select a secondary user that is not in transmitting or receiving mode to relay its traffic. The feasible relay location region and optimal power ratio between the primary network and the secondary network are derived in the underlay spectrum sharing model. Based on the optimal power ratio, we derive the maximum achievable transmission capacity of the secondary network under the outage constraints from both the primary and the secondary network with or without cooperative relaying. Numerical results indicate that secondary users can achieve a higher transmission capacity with cooperative relaying, and that the capacity gain of the cooperative network is significantly affected by the location of the relay and the network system parameters.