The 41-year-old had used his automatic assault rifle to fire at the United National Party headquarters, police said, adding that they were investigating his motive.
"There were no casualties, but some of the windows were damaged," a police official told AFP. He added that a replica of an elephant, the party symbol, was also hit during the shooting.
"The constable is in custody," added the official, who did not wish to be named.
The official said the man had previously been a police commando and was currently a sentry at the home of a top civil servant in charge of the Law and Order ministry.
More From This Section
Police had deployed over 7,000 constables to beef up security for 15 different May Day rallies which went off peacefully.
There were two deaths at one of the venues because of heat exhaustion, police and hospital sources said.
Sri Lanka routinely tightens security for May Day events since the assassination of president Ranasinghe Premadasa while attending a party procession 24 years ago.