Aims. We attempt to derive accurate transition probabilities for astrophysically interesting spectral lines of Nb II and Nb III and determine the niobium abundance in the Sun and metal-poor stars rich in neutron-capture elements. Methods. We used the time-resolved laser-induced fluorescence technique to measure radiative lifetimes in Nb II. Branching fractions were measured from spectra recorded using Fourier transform spectroscopy. The radiative lifetimes and the branching fractions were combined yielding transition probabilities. In addition, we calculated lifetimes and transition probablities in Nb II and Nb III using a relativistic Hartree-Fock method that includes core polarization. Abundances of the sun and five metal-poor stars were derived using synthetic spectra calculated with the MOOG code, including hyperfine broadening of the lines. Results. We present laboratory measurements of 17 radiative lifetimes in Nb II. By combining these lifetimes with branching fractions for lines depopulating the levels, we derive the transition probabilities of 107 Nb II lines from 4d(3)5p configuration in the wavelength region 2240-4700 angstrom. For the first time, we present theoretical transition probabilities of 76 Nb III transitions with wavelengths in the range 1430-3140 angstrom. The derived solar photospheric niobium abundance log epsilon(circle dot) = 1.44 +/- 0.06 is in agreement with the meteoritic value. The stellar Nb/Eu abundance ratio determined for five metal-poor stars confirms that the r-process is a dominant production method for the n-capture elements in these stars.