The code received widespread support during consultation and was unanimously approved by the Scottish Parliament.
It was introduced following concerns over the number of people being searched without a legal basis.
The code says statutory searches must be "necessary, proportionate and in accordance with the law". There is also specific guidance on dealing with children and vulnerable adults.
Non-statutory or "consensual" stop-and-searches are now banned entirely.
The new code was drawn up by an advisory group led by John Scott QC.
Justice Secretary Michael Matheson said: "The ability of police to stop and search individuals can be an intrusion into liberty and privacy, but remains a valuable tool in combating crime.
"I have spent some time with police officers using the new code on our streets and am in no doubt that such searches will be carried out with fairness, integrity and respect.
"The views expressed during the consultation period were absolutely key to shaping the new code."
The code states that stopping and searching must be done for a good reason and be both "necessary and proportionate".
This means that officers must have a "reasonable suspicion" based on "facts, information and/or intelligence" that the person being searched is likely to be carrying an illegal item.
Police Scotland Assistant Chief Constable Mark Williams said: "Police Scotland welcomes the introduction of the code and has worked closely with the Scottish government to support its development.
"It provides clear guidance to all our officers and places the rights of the individuals at the centre of any decision to carry out a search.
"In preparation for the introduction of the code, all frontline officers have received training and we will continue to work closely with partners, particularly children and young people, to monitor its impact."

He remains the world's richest person, despite giving away 64 million shares in Microsoft.
The shares are equivalent to 5% of his total fortune, currently estimated to be $89.9bn.
Since 1994 Mr Gates, 61, and his wife Melinda have given away a total of $35bn in cash and stocks to a range of charitable causes.
The donation was made in June but became public on Monday following the filing of a document with the US Securities and Exchange Commission.
Mr Gates' share in Microsoft is now just 1.3%. Prior to this, Mr Gates gave away $16bn in Microsoft shares in 1999 and $5.1bn in 2000.
The majority of all previous donations have been made to the Bill & Melinda Gates Foundation, which is primarily focused on reducing world poverty, combating infectious diseases and providing universal access to computers.
It is not known who the recipient of this latest donation is, however when federal documents are filed, it usually means new money is being given to a foundation, the Chronicle of Philanthropy reports.
In 2010, Mr and Mrs Gates and the well-known investor and philanthropist Warren Buffett created the Giving Pledge, and as of May 2017, 158 individuals or couples have agreed to contribute at least half of their wealth to charity.
This latest donation is the biggest charitable gift to have been made anywhere in the world so far this year.
The second largest was made by Mr Buffett, who donated almost $3.2bn to the Bill & Melinda Gates Foundation last month.
And the third biggest came from Dell Computer Corporation founder Michael Dell and his wife Susan.
In May the couple gave more than $1bn to their foundation, which focuses on children's issues and community initiatives.
A new code of practice on police stop-and-search powers has come into force.
[NEXT_CONCEPT]
Bill Gates has given away $4.6bn (Â£3.6bn) to charity in his largest donation since 2000.