The law, known as the NASA Transition Authorization Act, gives the space agency USD 19.5 billion in funding for fiscal year 2018. It also asks the agency to create a plan to send a "crewed mission to Mars in the 2030s."
Opening a new vista to human exploration of the space, Trump signed the bill in his Oval Office of the White House in the presence of the Vice President Mike Pence.
In his brief remarks, Trump praised the bill as a boon for NASA and a job creator.
"For almost six decades NASA's work has inspired millions and millions of Americans to imagine distant worlds and a better future right here on Earth. I'm delighted to sign this bill," Trump said.
"It's been a long time since a bill like this has been signed reaffirming our national commitment to the core mission of NASA, human space exploration, space science and technology," he said.
"With this legislation, we support NASA's scientists, engineers, astronauts and their pursuit of discovery. We support jobs. It's about jobs. Also this bill calls for ongoing medical monitoring and treatment of our heroic astronauts for health conditions that result from their service," Trump said.
Trump said the bill will make sure that NASA's most important and effective programmes are sustained.
"It orders NASA to...continue transitioning activities to the commercial sector where we have seen great progress. It's amazing what's going on," he said.
The bill he said continues support for the commercial crew programme which will carry American astronauts into space from American soil once again.
"It supports NASA's deep space exploration including the space launch system and the Orion spacecraft....It advances space science by maintaining a balanced set of mission and activities to explore our solar system and the entire universe and it ensures that, through NASA's astronauts and aeronautics research, the United States will remain a total leader in aviation," he said.
The NASA Acting Administrator, Robert Lightfoot, said the workforce has proven time and again that it can meet any challenge, and the continuing support for NASA ensures our nation's space programme will remain the world's leader in pioneering new frontiers in exploration, innovation, and scientific achievement.
"This law will promote innovation, support NASA's Space Launch System and Orion programmes, improve collaboration between the agency and commercial space sector, and benefit thousands of workers across Florida, particularly at Cape Canaveral and Kennedy Space Center," Senator Marco Rubio said in a statement.