Context. The prediction of stellar occultations by trans-Neptunian objects (TNOs) and Centaurs is a difficult challenge that requires accuracy both in the occulted star position and in the object ephemeris. Until now, the most used method of prediction, involving dozens of TNOs/Centaurs, has been to consider a constant offset for the right ascension and for the declination with respect to a reference ephemeris, usually the latest public version. This offset is determined as the difference between the most recent observations of the TNO/Centaur and the reference ephemeris. This method can be successfully applied when the offset remains constant with time, i.e. when the orbit is stable enough. In this case, the prediction even holds for occultations that occur several days after the last observations. Aims. This paper presents an alternative method of prediction, based on a new accurate orbit determination procedure, which uses all the available positions of the TNO from the Minor Planet Center database, as well as sets of new astrometric positions from unpublished observations. Methods. Orbits were determined through a numerical integration procedure called NIMA, in which we developed a specific weighting scheme that considers the individual precision of the observation, the number of observations performed during one night by the same observatory, and the presence of systematic errors in the positions. Results. The NIMA method was applied to 51 selected TNOs and Centaurs. For this purpose, we performed about 2900 new observations in several observatories (European South Observatory, Observatório Pico dos Dias, Pic du Midi, etc.) during the 2007-2014 period. Using NIMA, we succeed in predicting the stellar occultations of 10 TNOs and 3 Centaurs between July 2013 and February 2015. By comparing the NIMA and Jet Propulsion Laboratory (JPL) ephemerides, we highlight the variation in the offset between them with time, by showing that, generally, the constant offset hypothesis is not valid, even for short time scales of a few weeks. Giving examples, we show that the constant offset method cannot accurately predict 6 out of the 13 observed positive occultations that have been successfully predicted by NIMA. The results indicate that NIMA is capable of efficiently refining the orbits of these bodies. Finally, we show that the astrometric positions given by positive occultations can help to refine the orbit of the TNO and, consequently, the future predictions. We also provide unpublished observations of the 51 selected TNOs and their ephemeris in a usable format by the SPICE library.