Throughput maximization is one of the main challenges in cognitive radio ad hoc networks, where the availability of local spectrum resources may change from time to time and hop by hop. For this reason, a cross-layer opportunistic spectrum access and dynamic routing algorithm for cognitive radio networks is proposed, which is called the routing and dynamic spectrum-allocation (ROSA) algorithm. Through local control actions, ROSA aims to maximize the network throughput by performing joint routing, dynamic spectrum allocation, scheduling, and transmit power control. Specifically, the algorithm dynamically allocates spectrum resources to maximize the capacity of links without generating harmful interference to other users while guaranteeing a bounded bit error rate (BER) for the receiver. In addition, the algorithm aims to maximize the weighted sum of differential backlogs to stabilize the system by giving priority to higher capacity links with a high differential backlog. The proposed algorithm is distributed, computationally efficient, and has bounded BER guarantees. ROSA is shown through numerical model-based evaluation and discrete-event packet-level simulations to outperform baseline solutions, leading to a high throughput, low delay, and fair bandwidth allocation.