President Magufuli and his Ugandan counterpart Yoweri Museveni shook hands on the deal to build the 1,120-kilometer pipeline between the two countries during talks in Arusha on Tuesday.
The proposed pipeline will link oil fields in Uganda's Lake Albert, Hoima region to Tanga port in Tanzania, and serve as an export hub.
The project is expected to create more than 15,000 jobs and will be “for the benefit of both countries and other east African countries,” the Tanzanian leader's office said in a statement.
After their meeting in Arusha, Museveni applauded Magufuli for his alacrity and zeal in implementing projects, a factor seen by some observers as a major reason why Uganda picked Tanzania for this particular project instead of Kenya.
The Ugandan leader also has historically strong personal ties with Tanzania, which is where he launched the rebellion that brought him to power in his country in 1986.
Following some hard Kenyan lobbying, Uganda initially announced last year that it had agreed to route the pipeline through that country, but said Nairobi had to guarantee security for the project along with financing and cheaper fee options.
The Kenyan route had raised concerns over the fact that it would run through a region near the border with Somalia, from where Al-Shabaab Islamist militants from Somalia are known to regularly launch attacks on Kenya.
Kenya had also expressed plans to build a new port to serve the region alongside the pipeline.