Uganda discovered oil reserves in 2006 and needs the planned 1,445-km (900-mile) East African Crude Oil Pipeline to be in place to start commercial production. The pipeline is estimated to cost $3.5 billion, according to the two governments.
Hassan Abassi, Tanzania government spokesman, said on Twitter that 80% of the pipeline will run through Tanzania.
Tanzania will earn 7.5 trillion shillings ($3.24 billion) and create more than 18,000 jobs over the next 25 years, or more, that the project is in place, Abassi said after the signing ceremony attended by Tanzania's President John Magufuli and Ugandan President Yoweri Museveni in Chato, northwestern Tanzania.
Uganda has not given a date for when construction of the pipeline will begin but said last year that once construction begins, it would take 2-1/2 to three years to complete.
The agreement on the pipeline construction comes days after French oil company Total said it had reached an agreement with Uganda protecting its rights and obligations in the pipeline's construction and operation - known as the host government agreement.
Total is the major shareholder in Uganda's oilfields after agreeing in April to buy Tullow Oil entire stake in the jointly held onshore fields in Uganda for $575 million.
Tullow said last week it was confident of finalising the sale in the fourth quarter of this year.
The other partner in the 230,000 barrel-per-day project is China's CNOOC.
(Reporting by George Obulutsa; Editing by Susan Fenton)