Under the terms of the agreement, Exim Bank of China will provide 90 percent of the cost to replace the crumbling British colonial-era line with a 609.3 kilometre standard-gauge link and Kenya the remaining 10%.
Construction is due to start in October and take three-and-a-half years to complete, with China Communications Construction Co. as the main contractor.
Once the Mombasa-Nairobi line is completed, construction would begin to link east Africa's largest economy with Kampala, Kigali, Bujumbura and Juba.
The deal was signed at State House in Nairobi and witnessed by presidents Uhuru Kenyatta of Kenya, Yoweri Museveni of Uganda, Paul Kagame of Rwanda and Salva Kiir of South Sudan.
"This project demonstrates that there is equal cooperation and mutual benefit between China and the East African countries, and the railway is a very important part of transport infrastructure development," Chinese Premier Li Keqiang said.
Li has been on a four-country tour of Africa, his first since taking office last year, with the world's second-biggest economy keen to boost its presence on the continent to find new markets and opportunities.
Kenyatta hailed the booming relationship with China, calling it one "based on mutual trust" and saying Kenya "has found an honourable partner in China".
Museveni also took a swipe at Western donors who have been critical of his leadership -- including government corruption and his recent signing of draconian anti-gay legislation.
"We are happy to see that China is concentrating on the real issues of development," Museveni said.
"They don't give lectures on how to run local governments and other issues I don't want to mention," he said.