He was subsequently deprived of his post by Act of Parliament 11 June, and of Privy Council 1 October 1662. He was granted indulgence in
Dreghorn or at
Kilbirnie prior to 22 October 1674. He was ejected for non-conformity in 1663. In September 1672, he was ordered by the council, under the Act of Indulgence, to repair to the parish of Kilbirnie, and there to remain confined, with permission to preach and to exercise the other parts of his ministerial function, - which order he did not obey. In 1673, he was called before the council, and ordered to his confinement. He stayed in Edinburgh at Potterrow for some years but was called before the Privy Council, on 3 April 1678, on a charge of having held conventicles at
Boghall,
Biggar, and in his house during the years 1674–1648, and of corresponding with
John Welsh, Gabriel Semple, and other intercommuned persons such as Williamson and
Johnston. He appeared and denied the charge. He was pronounced guilty and sentenced to imprisonment on the Bass, unless he found caution to the amount of 2000 merks, and agreed to remove from Edinburgh and not come within five and a half miles of the city, or converse with any persons but the members of his own family. He found the necessary security, and retired to
Dalkeith, where he set up a meeting-house. He was released in July 1679. Anderson survived the Revolution, and on the ejection of Mr. John Kinked, an Episcopalian incumbent, he became minister of his old parish of Walston, where he laboured with great acceptance until he died. He was restored in 1689. He returned previous to 6 July 1689. He was restored by Act of Parliament 25 April 1690, and died 22 July following, aged about 63. ==Family==