The Scottish Prison Service (SPS) was informed yesterday morning by the Prison Officer Association (Scotland) that it was taking part in the action which flouted the seven-day notice period legally required.
Picket lines were set up at all but two jails, the privately-run Kilmarnock and Addiewell in West Lothian, as hundreds of thousands of public-sector staff went on strike across Britain.
Meanwhile, 30,000 members of the Public and Commercial Services Union in Scotland downed tools with protests at Holyrood, the Scottish Government, the Scotland Office, tax offices and courts over raising the pensionable age to 68 for recruits joining from 2015.
Pickets also gathered at Faslane nuclear base and Edinburgh and Stirling castles, with rallies held in Inverness, Dundee and Glasgow.
After learning of the action at jails, the SPS activated contingency plans. Many prisoners spent longer periods in their cells, having medication delivered in some cases.
The action stopped at 2.30pm following a meeting with John Ewing, chief executive of the SPS, and in light of a decision by colleagues in England and Wales to return to work.
An SPS spokesman said it was not yet known if any action would be taken against the union in Scotland over the lack of notice.
It is understood notice should have been given by the London-based executive committee which balloted on the strike.
The union claims that 68 is too old for prison officers to control a far younger prison population and is campaigning for the same pension entitlement as other uniformed services, such as police and firefighters.
Both the Scottish Government and the SPS have opposed the higher pensionable age but are hamstrung by the civil service pension scheme that is administered by the UK Treasury.
While prison officers in Scotland have a voluntary industrial relations agreement with SPS, with negotiation and arbitration key to resolution, members claimed the strike was its only mechanism to protest against Westminster policies.
Andy Hogg, Scottish secretary of the Prison Officer Association (Scotland), said: "What we did today was successful in terms of raising awareness over the issue of our pensions. We brought it to an end because we had achieved everything we wanted to achieve.
"In Scotland, our position is supported by our employers and the Government but everyone north of the Border is paralysed from addressing the issues."
He said the short notice to strike was given yesterday because the decision to take part was only made on Monday.
Mr Hogg added: "The meeting with the chief executive was an amicable one although he expressed disappointment the action was taken.
"We confirmed colleagues down south had gone back to work and on that basis we recognised what we achieved and agreed there was no reason to continue with any further disruption to services."
A total of 1553 Scottish Government staff went on strike – just over 22% of the workforce. All buildings remained open.
More strikes stretching into next year were threatened by union leaders last night as the Coalition insisted only a fraction of the predicted 400,000 public sector workers took action across the UK yesterday.
Francis Maude, the Cabinet Office Minister, praised the "dedicated majority" who had turned up for work, and insisted "rigorous contingency plans" had meant nearly all key public services had remained open.
Mr Maude said: "We can confirm that 102,244 civil servants were on strike yesterday, dramatically down from 146,000 in November."