The Fermanagh MLA Phil Flanagan tweeted after Tom Elliott appeared on a BBC radio programme in May 2014.
On Friday, the High Court was told the tweet read "Tom Elliott speaks to Steven Nolan about past.
"I wonder if he will reveal how many people he harassed and shot as a member of the UDR."
Mr Elliott served in the UDR for 10 years, between 1982 and 1992. He is now the MP for Fermanagh and South Tyrone
The High Court heard that he has a clear MoD record.
The court was told that Mr Elliott was alerted to the tweet by the victims campaigner Ann Travers and by DUP assembly member Arlene Foster, who is to become Northern Ireland first minister on Monday.
The tweet was deleted by Mr Flanagan within an hour of being posted.
The apology, which must also be posted on Twitter before the end of Friday, will state that the Sinn Féin MLA accepts that his tweet about Mr Elliott "was untrue and wholly without foundation".
Mr Justice Stevens has reserved judgement on the amount of compensation.
The court was also told that the insurance firm which indemnifies MLAs at Stormont, has refused to cover Mr Flanagan in respect of any compensation and costs in this case.
The Sinn Féin MLA is challenging that decision in a separate court action.
In a statement, Mr Elliott said: "I have been totally vindicated and Phil Flanagan has admitted that the comments he made were totally untrue. I am very disappointed that it has taken so long to get to this stage.
"This could have been resolved 19 months ago, but unfortunately I was forced to go down this route. Despite that, I am delighted with the result."
A Sinn Féin MLA has agreed to apologise and pay compensation to a former Ulster Unionist leader over a defamatory  message posted on Twitter.