We analyze the impact of post-innovation knowledge spillovers on firms' decisions to invest and cooperate in R&D, forming a research joint venture (RJV). We study the case of two potential investors involved in a non-tournament stochastic competition for developing a new but imitable product. We propose a theoretical model where cooperation may emerge as a subgame perfect Nash equilibrium of a three-stage game. In the first stage, firms decide whether to cooperate; in the second, they decide whether to invest; and in the third, they compete. We show that firms cooperate in R&D when the spillovers are high enough and the fixed costs associated with R&D activities are low enough; however, our analysis suggests that forming an RJV may not always be socially optimal, and subsidizing R&D cooperation may not be efficient. We propose an optimal scheme of subsidies, which should be designed according to the intensity of the spillovers, the level of the R&D costs, and the probability of innovation success. Finally, we show that in the case of mergers the private incentive to invest is maximized, and firms may not need public subsidies to cooperate. When subsidies are costly, not hindering mergers may be the second-best solution.