Community detection in networks is one of the most prominent areas of network science which is very hard and not yet satisfactorily solved. A hybrid algorithm based on particle swarm optimization (PSO) and Extremal Optimization (EO) for community detection is. PSO algorithm has strong global search ability but is easily to trap into the local optima, while EO algorithm can make the search to jump out of local optima due to its strong local search ability. A special encoding scheme based on the partition solution of a network is designed which can automatically determine the number of the community in a network. The popular modularity Q is used as the fitness of PSO algorithm and node betweenness centrality is adopted as the fitness of EO algorithm. EO algorithm can repair the isolated nodes existing in the particles and make the partition result more precise. Several experiments in real networks demonstrate that the algorithm obtains high modularity and achieves good community results.