Transport Minister Keith Brown said the towns were chosen to allow an overview of how a lower limit could work in different types of environment.
It is hoped that older people and cyclists will particularly benefit from the reduced speed limit.
Mr Brown announced that Largs and Maybole, in Ayrshire as well as Biggar in South Lanarkshire and Langholm, near Dumfries and Oban, in Argyll, will have 20mph limits imposed.
If successful the policy could be extended to other areas where there are higher accident rates.
Mr Brown said: "The safety of the trunk road network is a priority for Transport Scotland and managing speed is an important part of our strategy. It is essential that speeds are appropriate to conditions and these pilot zones will help us establish the benefits of lowering speeds in towns villages where it is reasonable to do so.
"The five trials are being proposed that will seek to improve road safety generally, but we expect them to bring specific benefits for vulnerable road users, such as older people and cyclists.
"There have been a number of calls for lower speed limits and specifically 20mph limits and we have had to whittle these down to a number that will give us a meaningful overview of how this will work in a variety of locations."
Some urban areas have already seen 20mph limits near primary schools, but this pilot includes the busy trunk road network.
Mr Brown added: "I know there will be some communities that are disappointed that they missed out but we will be looking at how their specific concerns can be addressed as part of our wider approach to speed management."
Chris Thompson, chairman of South Lanarkshire Council's Enterprise Services Committee, said: "We are firmly behind any proposals which make driving safer in our villages and towns.
"We have already introduced 20mph limits throughout the town to improve road safety and the plans now being brought forward for the A702 would complement those improvements."