The discovery will help scientists piece together the history of Mercury, the planet closest to the Sun and one about which we knew very little before the Messenger mission.
"The science from these recent observations is really interesting and what we have learned about the magnetic field is just the first part of it," said Catherine Johnson, planetary scientist from University of British Columbia and lead author of the study.
Scientists have known for some time that Mercury has a magnetic field similar to the Earth's but much weaker.
Mercury is the only other planet besides the Earth in the inner solar system with such a magnetic field.
There is evidence that Mars once had a magnetic field but it disappeared at some point over three billion years ago.
When Messenger flew close to the planet, its magnetometer collected data on the magnetism of rocks in Mercury's surface.
Those tiny signals revealed that Mercury's magnetic field is very ancient, between 3.7 and 3.9 billion years old.
The planet itself formed around the same time as the Earth, just over 4.5 billion years ago.
"If we did not have these recent observations, we would never have known how Mercury's magnetic field evolved over time," Johnson added.
The Messenger probe left the Earth in 2004, reached Mercury in 2008 and has orbited the planet since 2011, sending valuable data back to scientists.
Researchers used data obtained by Messenger in the fall of 2014 and 2015 when the probe flew incredibly close to the planet's surface - at altitudes as low as 15 km.
The paper was published in the journal Science Express.
For the latest tech news and reviews, follow Gadgets 360 on X, Facebook, WhatsApp, Threads and Google News. For the latest videos on gadgets and tech, subscribe to our YouTube channel. If you want to know everything about top influencers, follow our in-house Who'sThat360 on Instagram and YouTube.