* Atletico beat Real to keep up perfect start
* Barca set club record with win over Almeria
* Messi to have tests on hamstring injury (Updates with quotes, details)
By Mark Elkington
MADRID, Sept 28 (Reuters) - Atletico Madrid ended a run of 23 league derbies without a win when Diego Costa struck early to clinch a 1-0 victory over city rivals Real Madrid at the Bernabeu on Saturday.
Following up their 2-1 King's Cup final victory after extra time at the same venue in May, Atletico proved they had finally shaken off their inferiority complex with another gritty La Liga performance.
Brazilian striker Costa took his tally for the season to eight league goals when he broke away to score in the 11th minute, and Atletico could have avoided a nervy finale by putting away some of the clear chances they created.
Diego Simeone's side joined Barcelona at the top of the table with a maximum 21 points from seven games but are second on goal difference. Real stayed third with 16 points.
"We are delighted with the result and with the team effort," Atletico and Spain midfielder Koke told reporters.
"Title challengers? We are going to take it game by game."
For Real coach Carlo Ancelotti it was a severe setback to be left five points behind the top two while still in September, and the Italian was self-critical.
"We have to act after this with a better attitude and clearer ideas," he told a news conference.
"The moment isn't easy and we have to find a quick solution."
Earlier, Barca created a club record start to a league campaign with a 2-0 victory at promoted Almeria.
World Player of the Year Lionel Messi struck the opener after 21 minutes with a wonderful solo effort but was forced to leave the pitch soon after with a hamstring problem.
"Lionel has a little muscle problem in his right leg, something he did while scoring his goal," Barca coach Gerardo Martino told a news conference. "Until they do the tests we won't know anything more."
After a shaky spell just before halftime, Barca doubled their lead when Cesc Fabregas squared for Adriano to slide in and divert the ball into the corner to continue the home team's winless start to the season.
"All I have done is profit from what these guys have achieved," Martino told a news conference about the club record.
"They have been breaking records for years. Mine is merely circumstantial."
Valencia continued to recover from their poor start to the season with a 1-0 home win over basement side Rayo Vallecano.
Brazilian striker Jonas pounced on an error in the Rayo defence to net the only goal after 37 minutes, earning Miroslav Djukic's team a third consecutive victory that put them sixth with 12 points.
Real Sociedad are ninth with seven points after a 1-1 draw at home to Sevilla.
Antoine Griezmann levelled for Sociedad in the 66th minute to cancel out a great finish from Jairo in the 18th.
The Basques have now gone six games in La Liga and the Champions League without a win.
Real ran into familiar problems against Atletico as they struggled to break down an opponent who sat deep and gathered players behind the ball.
Home fans quickly became frustrated as passes went astray and the visitors threatened on the counter.
Atletico took the lead when Angel Di Maria was caught in possession near his own area. Koke played the ball through into space for Costa, who stroked a shot into the far corner.
Atletico's David Villa and Tiago should have done better with good first-half chances and tempers flared as some crunching tackles added spice to a derby lacking a little atmosphere because many Atletico fans had refused to pay the high ticket prices charged by their neighbours.
Real keeper Diego Lopez pulled off a great save on the line just before the break, and Ancelotti brought on Luka Modric and Gareth Bale for the second half.
It was a tough home debut for the world's most expensive player, who was brought down on the edge of the area for a freekick, though Cristiano Ronaldo blazed his effort into the stands.
Just seconds earlier, Lopez had saved from Costa in a one on one and Villa's follow up was blocked. The outstanding Koke later curled an effort against the crossbar.
Real piled forward near the end and the pressure grew until Thibaut Courtois made a spectacular save from a fierce Alvaro Morata volley in the dying minutes. (Reporting by Mark Elkington editing by Greg Stutchbury)