The Advocate General for Scotland, Lord Keen QC, said the Prime Minister will “take the necessary steps”.
However, while giving a legal undertaking on behalf of Mr Johnson, he refused to rule out the possibility the PM may advise the Queen to prorogue Parliament for a second time.
Lord Keen made the comments on Tuesday during an exchange with Lord Kerr, one of 11 justices hearing appeals arising out of two separate challenges in England and Scotland over the legality of the prorogation.
Each resulted in a different outcome.
When asked by Lord Kerr what would happen if the court rules that the prorogation was unlawful, and whether Parliament would be recalled, he replied: “It will be then for the Prime Minister to address the consequences of that declaration.”
Lord Keen added: “I have given a very clear undertaking that the Prime Minister will respond by all necessary means to any declaration that the … prorogation was effected by any unlawful advice that he may have given.”
When Lord Kerr asked if it could be taken that the prorogation decision could not be made a second time, Lord Keen replied: “I’m not in a position to comment on that.
“That will have to be addressed by the decision maker.”
Lord Keen added: “If the court finds it was unlawful, the Prime Minister will take the necessary steps to comply with any declaration made by the court.”
The lawyer, who is the chief legal adviser to the UK Government on Scottish law, is challenging the ruling of the Inner House of the Court of Session in Edinburgh.
The court ruled last week that Mr Johnson’s advice to the Queen was unlawful.
It said the move was “motivated by the improper purpose of stymying Parliament”.
Lord Carloway, Scotland’s most senior judge, said in the ruling: “The circumstances demonstrate that the true reason for the prorogation is to reduce the time available for parliamentary scrutiny of Brexit at a time when such scrutiny would appear to be a matter of considerable importance, given the issues at stake.”
That ruling, which was made following an appeal by a group including more than 70 parliamentarians led by SNP MP Joanna Cherry QC, overturned a previous decision that the suspension was lawful.
Lord Keen said the courts “must not cross the boundaries and intrude upon the business of Parliament”.
He also said the result of the prorogation was that Parliament would only lose “seven sitting days”.
He said this was because it would have been in recess for party conference season throughout most of the five weeks.
Lord Keen added: “It is quite plain that the Inner House, in addressing this issue and deciding that it could impugn the decision of the Prime Minister, was proceeding upon a fundamental misconception about how Parliament works.”
The Advocate General’s case is being heard alongside an appeal by campaigner Gina Miller, who is challenging a ruling of the High Court in London – which concluded that the length of the prorogation was “purely political” and not a matter for the courts.
Earlier on Tuesday, Mrs Miller’s barrister said the case raises “fundamental questions of constitutional law”.
Lord Pannick QC told the judges: “The exceptional length of the prorogation in this case is strong evidence that the Prime Minister’s motive was to silence Parliament for that period because he sees Parliament as an obstacle to the furtherance of his political aims.”
He also said it was a “remarkable feature” of the proceedings that Mr Johnson has not provided a statement explaining why he advised the Queen to suspend Parliament for the “exceptionally long period”.
Lord Pannick argued that the High Court “erred in law” in the case of Mrs Miller and that the Inner House of the Court of Session reached the “correct” conclusion as to Mr Johnson’s motive for proroguing Parliament.
Former prime minister Sir John Major, shadow attorney general Baroness Chakrabarti and the Scottish and Welsh governments – who supported Mrs Miller’s High Court challenge – are all interveners in the Supreme Court case.
Victims’ campaigner Raymond McCord – who brought separate proceedings in Belfast, arguing that a no-deal Brexit would damage the Northern Ireland peace process – is also an intervener.
Prorogation is the end of a parliamentary session brought about other than by the dissolution of Parliament before a general election.
Mr Johnson advised the Queen on August 28 to prorogue Parliament for five weeks and it was suspended on September 9.
The Prime Minister says the suspension is to allow the Government to set out a new legislative agenda in a Queen’s Speech when MPs return to Parliament on October 14.
But those challenging his decision argue that it is designed to prevent parliamentary scrutiny of the UK’s impending exit from the EU on October 31.
The Supreme Court justices are being asked to determine whether the Prime Minister’s advice to the Queen is “justiciable” – capable of challenge in the courts – and, if so, whether it was lawful.
The court will hear further submissions from the parties and the interveners on Wednesday and Thursday, but it is not clear when a ruling will be given.
A crowd of about 40 protesters, holding signs saying “Defend democracy”, “Reopen Parliament” and “They misled the Queen”, remained outside the Supreme Court throughout the hearing.
A smaller number of pro-Brexit demonstrators, including one who shouted “traitor” at Mrs Miller as she left court, also gathered outside the historic building on Parliament Square.
Ahead of the hearing, Mrs Miller – who previously brought a successful legal challenge over the triggering of the Article 50 process to start the Brexit countdown – described the prorogation decision as “a classic power-grab”.
Ms Cherry said she was “cautiously optimistic” the Supreme Court would uphold the Scottish ruling.
Lawyers for the Prime Minister will outline his case that his advice on the suspension was lawful from 10.30am on Wednesday.
Additional reporting by PA.