Special Chief Judicial Magistrate Himanshu Dayal Srivastava passed the order on an application moved by Inspector Pankaj Awasthi of the Anti-Terrorism Squad (ATS) of the Uttar Pradesh Police.
The custody remand period would begin on Thursday at 9 pm.
Agrawal was arrested Monday in a joint operation by the Uttar Pradesh Police and their Maharashtrian counterpart at BrahMos' Wardha Road facility in Nagpur for allegedly leaking "technical information" to Pakistan.
He was flown to Lucknow From Nagpur.
The ATS Thursday sought his custody from the court for the purpose of interrogation.
Agarwal's lawyer opposed the remand, pleading that he was a young scientist who is being implicated as part of a "conspiracy".
It is alleged that Agrawal was in contact with two Facebook accounts -- 'Neha Sharma' and 'Pooja Ranjan' -- suspected to be operated by Pakistani intelligence agents.
He has been booked under the Official Secrets Act.
BrahMos Aerospace is a joint venture between India's Defence Research and Development Organisation (DRDO) and the 'Military Industrial Consortium' (NPO Mashinostroyenia) of Russia.
(With inputs from agencies.)