It will be invested in a new national network which will see pupils work with universities and other experts.
In a major study, Welsh students were below the average of 72 countries in science, reading and maths.
Education Secretary Kirsty Williams said: "This new network of excellence is part of our national mission of education reform to raise standards."
The Pisa results in December marked the fourth time Wales has done worse than the other UK nations.
This planned network will pull together teaching practices for three to 18-year-olds, look at how other countries teach the subjects and allow schools to work together to develop courses and teaching.
Ms Williams said the investment was not a "knee jerk" reaction to the Pisa results but a "carefully considered response".
"An understanding of science is crucial for our young people, from the technology they use, the way they communicate, through to the energy they use in a rapidly changing world," she said.
"The science Pisa results chimed with our own understanding that we are not where we wish to be.
"This new network of excellence is part of our national mission of education reform to raise standards."
The announcement has been welcomed by academics.
Prof Tom Crick, who teaches computer science and public policy at Cardiff Metropolitan University, told BBC Radio Wales' Good Morning Wales programme it would help improve teaching standards.
"You don't want to have to look at this £4m and divide it by the number of schools and the number of teachers," he said.
"I think we are looking at a wider national picture but still addressing regional and local issues.
"Ultimately the biggest impact will be spent on professional development of teachers... that is where we will give the biggest bang for the buck from the investment, directly addressing teachers' competencies."
More than £4m will be spent to raise standards in science and technology in Welsh schools.