A metrized complex of algebraic curves over an algebraically closed field \(\kappa \) is, roughly speaking, a finite metric graph \(\Gamma \) together with a collection of marked complete nonsingular algebraic curves \(C_v\) over \(\kappa \), one for each vertex \(v\) of \(\Gamma \); the marked points on \(C_v\) are in bijection with the edges of \(\Gamma \) incident to \(v\). We define linear equivalence of divisors and establish a Riemann–Roch theorem for metrized complexes of curves which combines the classical Riemann–Roch theorem over \(\kappa \) with its graph-theoretic and tropical analogues from Amini and Caporaso (Adv Math 240:1–23, 2013); Baker and Norine (Adv Math 215(2):766–788, 2007); Gathmann and Kerber (Math Z 259(1):217–230, 2008) and Mikhalkin and Zharkov (Tropical curves, their Jacobians and Theta functions. Contemporary Mathematics 203–231, 2007), providing a common generalization of all of these results. For a complete nonsingular curve \(X\) defined over a non-Archimedean field \(\mathbb {K}\), together with a strongly semistable model \(\mathfrak {X}\) for \(X\) over the valuation ring \(R\) of \(\mathbb {K}\), we define a corresponding metrized complex \(\mathfrak {C}\mathfrak {X}\) of curves over the residue field \(\kappa \) of \(\mathbb {K}\) and a canonical specialization map \(\tau ^{\mathfrak {C}\mathfrak {X}}_*\) from divisors on \(X\) to divisors on \(\mathfrak {C}\mathfrak {X}\) which preserves degrees and linear equivalence. We then establish generalizations of the specialization lemma from Baker (Algebra Number Theory 2(6):613–653, 2008) and its weighted graph analogue from Amini and Caporaso (Adv Math 240:1–23, 2013), showing that the rank of a divisor cannot go down under specialization from \(X\) to \(\mathfrak {C}\mathfrak {X}\). As an application, we establish a concrete link between specialization of divisors from curves to metrized complexes and the theory of limit linear series due to Eisenbud and Harris (Invent Math 85:337–371, 1986). Using this link, we formulate a generalization of the notion of limit linear series to curves which are not necessarily of compact type and prove, among other things, that any degeneration of a \(\mathfrak {g}^r_d\) in a regular family of semistable curves is a limit \(\mathfrak {g}^r_d\) on the special fiber.