A car bomb exploded in the heart of the Somali capital on Wednesday, wounding two people, and the rebel al Shabaab group said its members had carried out the attack.

Hours later, four civilians were killed and seven wounded when a grenade was thrown into a government tax office in the southern city of Baidoa, witnesses said.

The Mogadishu blast, which triggered bursts of gunfire in the city, was the latest in a wave of bomb attacks in the country where the embattled U.N.-backed government is struggling to secure the city against al Qaeda-linked Islamist rebels.

We were behind the car bomb explosion. We targeted security forces, Sheikh Abdiasis Abu Musab, a spokesman for al Shabaab military operations, told Reuters of the blast in the busy administrative district, near the bustling Kilometre 4 junction.

Police said four suspects had been detained and that they were investigating a second suspicious vehicle in the city.

There has been a surge in suicide bombings and remotely detonated blasts in Mogadishu since al Shabaab pulled most of its fighters out of the coastal city in August, vowing to turn increasingly to al Qaeda-inspired tactics.

Al Shabaab carried out a truck bombing in October which killed more than 70 people, its deadliest attack since the rebellion began in 2007. A spate of smaller attacks followed.

The militants have been weakened in past months, on the back foot against African Union soldiers in Mogadishu and losing territory to Kenyan and Ethiopian forces in southern and central Somalia. There are also signs of growing internal divisions within the rebel ranks.

Piracy has also flourished in the chaos of the last two decades. On Wednesday, pirates freed British hostage Judith Tebbutt more than six months after seizing her and shooting dead her husband, saying they had received a ransom.

ATTACK IN BAIDOA

In Mogadishu, witnesses told Reuters the explosives-packed car had been parked on Maka al Mukarram road between K4 and the presidential palace, arousing the suspicions of security forces who blocked off traffic.

We got a man with the remote control seconds after he detonated the car. We also arrested three other suspects, police spokesman Abdullahi Barise said.

A Reuters photographer who saw the wrecked car said one of the wounded, who was taking photos of the vehicle when it blew up, was bleeding heavily and crying out in pain as onlookers helped him. One family fled their house just metres away moments before the bomb exploded.

Several hours later, police said they had cordoned off the K4 intersection to investigate another vehicle abandoned in an area used by waiting taxis.

We didn't recognise the car. All taxi drivers fled the parking. It is a suspected car bomb, witness Jama Hussein said. Security forces were holding people back.

In the southern city of Baidoa, which Ethiopian and Somali troops seized from al Shabaab last month, witnesses said at least four civilians were killed and seven wounded when a grenade was hurled at a recently reopened government tax office.

The tax office is in the market. Traders have been paying cash to al Shabaab for the last three years. Now the government started collecting tax after it ousted them, Baidoa shopkeeper Hassan Abdiqader told Reuters.

Losing control of Baidoa was considered a major tactical blow to al Shabaab, which is battling Kenyan troops to hold on to territory in southern Somalia and fighting African Untion troops around the capital.

(Additional reporting by Mohamed Ahmed in Nairobi; Writing by Richard Lough; Editing by Yara Bayoumy and Tim Pearce)